I save the changes in the database by clicking on the button, here is the code itself:
I have several blocks of such code for each ComboBox item
All of them are the same, but it gives an error on this one, why can this be so?
An example of a working block:
I also know that the error occurs in the line:
What am i doing wrong?
C#:
else if (comboBox1.SelectedItem == "Работа")
{
label3.Text = "Работа";
string script = "SELECT id, name, Model_preparation_R_Hr, Time_for_preparation_hr, Time_for_post_processing_hr, YZV_work FROM rabota;";
mycon = new MySqlConnection(connect);
mycon.Open();
MySqlDataAdapter ms_data = new MySqlDataAdapter(script, connect);
var cb = new MySqlCommandBuilder(ms_data);
cb.GetInsertCommand();
DataSet ds = new DataSet();
ms_data.Update(dataGridView1.DataSource as DataTable);
ms_data.InsertCommand = cb.GetInsertCommand();
ms_data.InsertCommand.CommandText += "; select * from rabota where id = last_insert_id();";
ms_data.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
}
I have several blocks of such code for each ComboBox item
All of them are the same, but it gives an error on this one, why can this be so?
An example of a working block:
C#:
else if (comboBox1.SelectedItem == "Rash")
{
label3.Text = "rash";
string script = "SELECT id, name, Spirt_10_Litr, gloves, knife, detergent_PH11_Litr FROM rash;";
mycon = new MySqlConnection(connect);
mycon.Open();
MySqlDataAdapter ms_data = new MySqlDataAdapter(script, connect);
var cb = new MySqlCommandBuilder(ms_data);
cb.GetInsertCommand();
ms_data.Update(dataGridView1.DataSource as DataTable);
ms_data.InsertCommand = cb.GetInsertCommand();
ms_data.InsertCommand.CommandText += "; select * from rash where id = last_insert_id();";
ms_data.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;
}
I also know that the error occurs in the line:
C#:
ms_data.Update(dataGridView1.DataSource as DataTable);
What am i doing wrong?
Last edited by a moderator: