hi,
how can i insert the values into sql database
ex:manish,rama,raju etc.......
these fields are inserted into table.may be the fields are 3 or 4 or etc.not particular numbers
please help me.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 10:22 PM EDT
First you need to change the Table definatition of TableMain as shown below
CREATE TABLE TableMain
Then if you want keep duplicate value then modify the SP as shown below
ALTER PROCEDURE dbo.[usp_SaveCommaSeparatedValue]
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 4:17 AM EDT
http://www.w3schools.com/sql/sql_insert.asp
If you're doing this from .NET, then the precise code will depend on which database you're using as there are different 'providers' available. This link applies to SQL Server:
http://msdn.microsoft.com/en-us/library/ms233812(v=vs.100).aspx
prathyusha173 reputationPosted Jun 25, 2013, 4:23 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 4:24 AM EDT
You can do like below
protected void BtnSave_Click(object sender, EventArgs e)
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
prathyusha173 reputationPosted Jun 25, 2013, 4:32 AM EDT
aaa
bc
ccc
and one more thing that string not contains particular number of parts. it may be 1 or 3 or like.
please help me.....
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 4:43 AM EDT
There is two way you can do this. First tell me are you trying to insert the data directly from your code or by using Stored Procedure?
Regards,
Iftikar
prathyusha173 reputationPosted Jun 25, 2013, 4:46 AM EDT
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 7:21 AM EDT
First create one User Defined Function in sql as shown below
Then create on new SP and pass comma separated value into it
exec usp_SaveCommaSeparatedValue 'aaa,bbb,cccc'
Let me know if you need more information
If your SQL version is 2005 or 2000 then I will provide different solution
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
VulpesRank #55 · 29.2K reputationPosted Jun 25, 2013, 3:32 PM EDT
prathyusha173 reputationPosted Jun 25, 2013, 9:21 PM EDT
thank u very much for your help.
exec dbo.[usp_SaveCommaSeparatedValue] 'aaa,bbb,cccc' it is working and inserted successfully.
but when i execute that procedure second time like
exec dbo.[usp_SaveCommaSeparatedValue] 'd2,t3,ty4'
this error will be displayed
Msg 2627, Level 14, State 1, Procedure usp_SaveCommaSeparatedValue, Line 8 Violation of PRIMARY KEY constraint 'PK__TableMai__DC501A787132C993'. Cannot insert duplicate key in object 'dbo.TableMain'. The statement has been terminated.
and by using coding
please help me.it's very important to me
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 9:37 PM EDT
before inserting the data into Table, always execute the delete statement with the primary key condition.
DELETE FROM TableMai WHERE PK_Column=value
Let me know if you need more information
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
prathyusha173 reputationPosted Jun 25, 2013, 9:40 PM EDT
please help me
prathyusha173 reputationPosted Jun 25, 2013, 9:56 PM EDT
how can we insert depending on length.
please help me
Iftikar HussainRank #423 · 5.9K reputationPosted Jun 25, 2013, 9:59 PM EDT
Regards,
Iftikar
prathyusha173 reputationPosted Jun 25, 2013, 10:04 PM EDT
( @Input varchar(1000) )
AS SET NOCOUNT ON
DELETE FROM dbo.[TableMain] WHERE value=value
INSERT INTO dbo.[TableMain](idx,Value)
SELECT idx,value FROM [dbo].[udf_SplitCsvToTable](@Input,',') SET NOCOUNT OFF
exec dbo.[usp_SaveCommaSeparatedValue] 'aaa,bbb,cccc' output like this
exec dbo.[usp_SaveCommaSeparatedValue] 'aarra,bbb,cccc' first recod is deleted
but i need like this
please help me
prathyusha173 reputationPosted Jun 25, 2013, 10:52 PM EDT
JosephsRank #1,506 · 1.1K reputationPosted Jul 3, 2013, 6:17 AM EDT
Iftikar Hussain
why using using block what is advantages?
Bineesh ViswanathRank #1,680 · 907 reputationPosted Jul 5, 2013, 11:36 AM EDT
i don't know how much fields your table has.
A database will became unfruitful if the same group of values being repeated.
to avoid these, u need a condition in the stored procedure.
In variable declaration, can avoid Pk_column in insert because it will auto generated if set this to IDENTITY
here is the stored procedure to insert data into database.
CREATE PROCEDURE tbl_Name
// variable declaration
@name nvarchar(20),
//condition to avoid data duplication
if not exists(select name from tbl_Name where name=@name)
begin
insert into tbl_Name(name)
values(@name)
end
this statement is an easy way to add as we don't have to go table each time of insertion.
when execute being clicked, a window opens for enter the name into the table.
if this statement tested successfully, accept it.
manjula d131 reputationPosted Jul 8, 2013, 4:09 AM EDT