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