I have a problem when I try to update the data in my table, it sends me this error:
incorrect syntax near the key word 'UPDATE'. ...
You have to use a parameter in the code and NEVER concatenate in the string
The structure should look like the following:
using (SqlConnection conn = new SqlConnection("<connection string>"))
{
conn.Open();
string query = "UPDATE NombreTabla SET campo1=@param1, campo2 = @param2 WHERE id = @paramid";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.AddWithValue("@param1", TextBox1.Text);
cmd.Parameters.AddWithValue("@param2", Convert.ToInt32(Textbox2.Text));
cmd.Parameters.AddWithValue("@paramid", Convert.ToInt32(Textbox3.Text));
cmd.ExecuteNonQuery();
}
If the method you use cnn.update () does not let you assign parameters then you should change it, maybe define a List<SqlParameter>
to be able to specify from the outside the parameters that you assign to the update