Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Insert in Sql table
Message
De
13/01/2005 00:53:08
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Bases de données
Divers
Thread ID:
00976656
Message ID:
00976669
Vues:
7
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform