latinskyscraper
New Member
I wonder why I got this runtime error by throwing this exception: \[quote\] SqlException was unhandled by user code Incorrect syntax near 'm'.
Unclosed quotation mark after the character string ')'.\[/quote\]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:\[code\]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");}\[/code\]
Unclosed quotation mark after the character string ')'.\[/quote\]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:\[code\]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");}\[/code\]