Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Insert in Sql table
Message
From
13/01/2005 00:53:08
 
 
General information
Forum:
ASP.NET
Category:
Databases
Miscellaneous
Thread ID:
00976656
Message ID:
00976669
Views:
8
Bharat,

You need to use SqlCommand Parameters. Here's an example:
SqlCommand sc = new SqlCommand(MyConnection);
sc.CommandText = "INSERT INTO MyTable (MyKey) VALUES (@Key)";
sc.Parameters.Add("@Key", 123);
sc.ExecuteNonQuery();
~~Bonnie


>Hi,
> I am trying to insert data in sql server in C#.
>When I write
>string insertstring = @"insert into _4_claim_dbf_temp(batch_num, TKS_NO, claim_num, Client)values('ll1111', 'l1111l', '22222', 'Lp')";
>and use
>cmd3=new SqlCommand(insertstring,conn3);
>cmd3.ExecuteNonQuery();
>This works fine but in the above query if I use variables in the values part, like
>string insertstring = @"insert into _4_claim_dbf_temp(batch_num, TKS_NO, claim_num, Client)values(batch_num, TKS_NO, CLAIM_NUM, 'Lp')";
>where batch_num and other variables gets value like
>string batch_num = pRow["org_batch"].ToString();
>batch_num = batch_num.Trim();
>
> I get exception error. Where am I wrong here.
>
>Thanks
>Bharat
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform