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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Iftikar HussainPosted Jun 26, 2013, 2:22 AM
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.
manjula dPosted Jul 8, 2013, 8:09 AM
Bineesh ViswanathPosted Jul 5, 2013, 3:36 PM
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.
JosephsPosted Jul 3, 2013, 10:17 AM
Iftikar Hussain
why using using block what is advantages?
prathyushaPosted Jun 26, 2013, 2:52 AM
prathyushaPosted Jun 26, 2013, 2:04 AM
( @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
Iftikar HussainPosted Jun 26, 2013, 1:59 AM
Regards,
Iftikar
prathyushaPosted Jun 26, 2013, 1:56 AM
how can we insert depending on length.
please help me
prathyushaPosted Jun 26, 2013, 1:40 AM
please help me
Iftikar HussainPosted Jun 26, 2013, 1:37 AM
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.
prathyushaPosted Jun 26, 2013, 1:21 AM
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
VulpesPosted Jun 25, 2013, 7:32 PM
Iftikar HussainPosted Jun 25, 2013, 11:21 AM
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.
prathyushaPosted Jun 25, 2013, 8:46 AM
Iftikar HussainPosted Jun 25, 2013, 8:43 AM
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
prathyushaPosted Jun 25, 2013, 8:32 AM
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 HussainPosted Jun 25, 2013, 8:24 AM
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.
prathyushaPosted Jun 25, 2013, 8:23 AM
VulpesPosted Jun 25, 2013, 8:17 AM
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