I want to ask how to update data in database? I'm using the code as the below.

    string value1 = TextBox1.Text;
    string value2 = TextBox2.Text;
    string value3 = TextBox3.Text;
    string value4 = TextBox4.Text;
    string value5 = TextBox5.Text;

    string strsql = "Update Form Set Name='" + TextBox2.Text + "', Designation='" + TextBox3.Text + "',Mobile_No='" + TextBox4.Text + "' Address='" + TextBox5.Text + "' where Id='" + TextBox1.Text + "';

    dbComm = new SqlCommand(strsql, dbConn);
    int rc = dbComm.ExecuteNonQuery();

Recommended Answers

You need a comma before Address=

Jump to Post

All 4 Replies

I hope anyone can help me to solved this problem. The problem at line 7.


You need a comma before Address=

In addition, while that will fix the sytnax error, the other problem that you should address is that your approach exposes you to SQL injection. Use parameterized queries instead.

Also, I see a single quote outside of the double quote after textbox1, at the end.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.