H
H
HelpIT2021-01-11 21:52:38
SQL
HelpIT, 2021-01-11 21:52:38

System.Data.SqlClient.SqlException: "Incorrect syntax near 'studentNo'." how to solve the problem?

System.Data.SqlClient.SqlException: "Incorrect syntax near 'studentNo'." when i click update button

protected void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["StudentConnectionString"].ConnectionString);
            conn.Open();
            string updateQuery = "update Students set firstName = '"+ txtBoxfName + "', lastName = '"+ txtBoxlName +"' studentNo = '" + Convert.ToInt32(txtBoxStudentNo.Text) + "' where id_student = '"+ Convert.ToInt32(txtPK.Text) +"'";
            SqlCommand cmd = new SqlCommand(updateQuery, conn);
            cmd.ExecuteNonQuery();
            Label2.Text = "student successfully updated";

            txtBoxfName.Text = " ";
            txtBoxlName.Text = " ";
            txtBoxStudentNo.Text = " ";

        }

5ffc9e72889d0734841789.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-01-11
@HelpIT

The comma is missing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question