Home » c# » c# – CS1009: Unrecognized escape sequence error when debugging-Exceptionshub

c# – CS1009: Unrecognized escape sequence error when debugging-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

I’m currently having trouble when clicking the “Add Student” button in my CreateStudent page. After running the program, it redirects to this line that these error occurs when debugging

SqlException was unhandled by user code

~~~protected void Page_Load(object sender, EventArgs e)
{
    con.ConnectionString="Data Source=DESKTOP-EB4EK81\SQLEXPRESS; Initial Catalog=TACLC; Integrated Security=True";
    con.Open();
}~~~
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;


public partial class CreateStudent : System.Web.UI.Page
{
    SqlCommand cmd = new SqlCommand();
    SqlConnection con = new SqlConnection();


    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString="Data Source=DESKTOP-EB4EK81\SQLEXPRESS; Initial Catalog=TACLC; Integrated Security=True";
        con.Open();
    }
    protected void btnCreateStudent_Click(object sender, EventArgs e)
    {

        //SqlCommand cmd = new SqlCommand();
        //SqlConnection con = new SqlConnection();
        SqlCommand cmd = new SqlCommand("insert into tbl_Createstudent" + "(txtFirstName, txtLastName, txtGrade, Gender, txtAddress, txtGuardianPhoneNumber)values(@txtFirstName, @TxtLastName, @TxtGrade, @Gender, @txtAddress, @TxtGuardianPhoneNumber)", con);
        cmd.Parameters.AddWithValue("@txtFirstName", txtFirstName.Text);
        cmd.Parameters.AddWithValue("@txtLastName", txtLastName.Text);
        cmd.Parameters.AddWithValue("@txtGrade", txtGrade.Text);
        cmd.Parameters.AddWithValue("@Grade", DropDownList1.SelectedItem.Value);
        cmd.Parameters.AddWithValue("@txtAddress", txtAddress.Text);
        cmd.Parameters.AddWithValue("@txtGuardianPhoneNumber", txtGuardianPhoneNumber.Text);
        cmd.ExecuteNonQuery();
        Label1.Text = "Adding Student Successful";

    }
}~~~
How to&Answers: