SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString);
con.Open();
Int32 code = Convert.ToInt32(TextBox1.Text);
String name = TextBox2.Text;
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into tbmem (memcod,memnam) values (@code,@name)" ;
cmd.Connection = con;
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
Error : must declare @code scalar variable
Thanks
VulpesPosted Jun 20, 2011, 11:47 AM
Check out this link (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx) for an example of how to do this using the Add or AddWithValue methods.