Click here to Skip to main content
15,892,737 members

Response to: apostrophe s problem in sql query

Revision 2
use this type

String cs = WebConfigurationManager.ConnectionStrings["conm"].ConnectionString;
SqlConnection conn = new SqlConnection(cs);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.text;
cmd.CommandText = "insert into table (name,address,comment) values(@name,@address,@comment)";

cmd.Parameters.Add("@name", SqlDbType.VarChar).Value = txtname.text ;
cmd.Parameters.Add("@address", SqlDbType.VarChar).Value = txtaddress.text;
cmd.Parameters.Add("@comment", SqlDbType.VarChar).Value = txtcomment.text;

cmd.ExecuteNonQuery();
conn.Close();
Posted 18-Jan-13 19:40pm by kanjolia gopal.
Tags: ,