I am trying to update my MySql database but it won’t work. I have inserting and selecting working fine. Not sure if it is my syntax on the query or what.
string id = invoicenumb.Text;
string mysqlIns1 = "UPDATE invoices SET Status = '" +
comboBox1.SelectedItem.ToString() + "' WHERE id = '" +
Convert.ToInt16(id) + "'";
try
{
MySqlConnection mysqlCon = new MySqlConnection(mysqlProv);
mysqlCon.Open();
MySqlDataAdapter MyDA = new MySqlDataAdapter();
MyDA.SelectCommand = new MySqlCommand(mysqlIns1, mysqlCon);
MessageBox.Show("Success!");
mysqlCon.Close();
}
catch
{
MessageBox.Show("Error Occured Please Try Again");
}
Use
UpdateCommandinstead ofSelectCommand.See MySqlDataAdapter.UpdateCommand Property