Click here to Skip to main content
15,911,785 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I could not insert data into my sql table with the following code.
C#
SqlCommand com = new SqlCommand("insert into txfile mem_id=(@C1), reg_id=(@C2)", con);
                com.Parameters.AddWithValue("@C1", v_mem_id);
                com.Parameters.AddWithValue("@C2", v_reg_id);
                com.ExecuteNonQuery();


I get no error.
Can anyone guide?
Posted
Updated 9-Jul-13 22:07pm
v2

hi,

you are using wrong way for insert statement


use it like..

SqlCommand com = new SqlCommand("insert into txfile(mem_id,reg_id) values(@C1, @C2)", con);
com.Parameters.AddWithValue("@C1", v_mem_id);
com.Parameters.AddWithValue("@C2", v_reg_id);
con.Open();
com.ExecuteNonQuery();
con.Close();
 
Share this answer
 
C#
SqlCommand com = new SqlCommand("INSERT INTO txfile (mem_id, reg_id) VALUES (@C1, @C2);", con);
com.Parameters.AddWithValue("@C1", v_mem_id);
com.Parameters.AddWithValue("@C2", v_reg_id);
com.ExecuteNonQuery();
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900