Chidiebere Mgbemena

Chidiebere Mgbemena

  • NA
  • 179
  • 13.8k

Error in updating products on datagridview c#

Apr 17 2020 4:08 PM
I got this error below while trying to update product table:
 
Unclosed quotation mark after the character string " where ProID=''. Incorrect syntax near "where ProID =''.
 
My codes:
  1. private void btnUpdate_Click(object sender, EventArgs e)  
  2. {  
  3. try  
  4. {  
  5. con.Open();  
  6. cmd = new SqlCommand("UPDATE tbl_Products SET ProName='" +txtProName.Text+"' where ProID='"+txtProID.Text+"' ", con);  
  7. cmd.ExecuteNonQuery();  
  8. con.Close();  
  9. MessageBox.Show("Product Info Saved...");  
  10. fillGrid();  
  11. cleartext();  
  12. }  
  13. catch (Exception ex)  
  14. {  
  15. MessageBox.Show(ex.Message);  
  16. }  
  17. con.Close();  
  18. {  
  19. }  
  20. }  
  21. private void cleartext()  
  22. {  
  23. txtProID.Text = "";  
  24. txtProName.Text = "'";  
  25. }  
  26. }  
  27. }  
Please help me find the unclosed quotation
thanks

Answers (2)