Im getting fatal error during command execution when I add the WHERE clause which is the ID
MySqlCommand MyCommand2 = new MySqlCommand("UPDATE student SET name =@Name, gender = @Gender, course =@Course, section = @Section, violation = @Violation, action = @Action, manual =@Manual, report = @Report, date = @Date ,img = @Img WHERE ID = @id ", MyConn2);
//
MyCommand2.Parameters.AddWithValue("@Name", name_tf.Text);
MyCommand2.Parameters.AddWithValue("@Gender", gender_tf.Text);
MyCommand2.Parameters.AddWithValue("@Course", course_tf.Text);
MyCommand2.Parameters.AddWithValue("@Section", yr_tf.Text);
MyCommand2.Parameters.AddWithValue("@Violation", vio_tf.Text);
MyCommand2.Parameters.AddWithValue("@Action", taken_cb.Text);
MyCommand2.Parameters.AddWithValue("@Manual", manual_tf.Text);
MyCommand2.Parameters.AddWithValue("@Report", report_tf.Text);
MyCommand2.Parameters.AddWithValue("@Date", date_tf.Text);
MyCommand2.Parameters.AddWithValue("@Img", arr);
My questions are;
- How can I implement it in where clause correctly since my ID is PK which is not user input?
- How to avoid updating all the data in database even you selected specific data only?
SOLVE!! how did i do it? so here;
int i; // global variable
I put this code on the property of DataGridView which is CellClick
i = Convert.ToInt32(stud_tbl.CurrentRow.Cells[0].Value);
I add this in mysqlcommand
MyCommand2.Parameters.AddWithValue("@id", i);
that's all thanks everyone who commentend!