I wonder why I got this runtime error by throwing this exception:
SqlException was unhandled by user code
Incorrect syntax near 'm'.
Unclosed quotation mark after the character string ')'.
When I used this code below to add records into my database when in fact I always used this code every time, now its not working.
I hope you can figure out the cause of this error. Thanks...Here's the code below:
protected void Button1_Click(object sender, EventArgs e)
{
string conn = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Coldwind.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlConnection connection = new SqlConnection(conn);
// SqlDataReader dr = new SqlDataReader();
connection.Open();
string sql = "INSERT INTO [CommentTab]([Name],[Comments]) Values('" + TextBox1.Text + "','" + TextBox2.Text + "')";
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
cmd.Dispose();
connection.Close();
Response.Redirect("~/Default5.aspx");
}