在dataGridView中保存更改的方法



我有一个包含8个表的数据库,我填充我的datagridview,然后使用相同的代码块为每个表保存更改,但我只能保存8个表中的4个,其他4个表会给我一个错误Concurrency violation: the UpdateCommand affected 0 of the expected 1 records当我试图保存中的更改时

这就是我填充数据的方式GridView:

{
string script = "SELECT * FROM hatr.rbt;";
mycon = new MySqlConnection(connect);
mycon.Open();
MySqlDataAdapter ms_data = new MySqlDataAdapter(script, connect);
SD.DataTable table = new SD.DataTable();
ms_data.Fill(table);
DataSet ds = new DataSet();
dataGridView1.DataSource = table;
mycon.Close();
ds.AcceptChanges();
}

这就是我保存更改的方式:

{
string script = "SELECT id, name, Model_preparation_R_Hr, Time_for_preparation_hr, Time_for_post_processing_hr, YZV_work FROM rbt;";
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 rbt where id = last_insert_id();";
ms_data.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;        
}

我也知道错误发生在以下行:

ms_data.Update(dataGridView1.DataSource as DataTable);

对于每个表,这两个代码块都是相同的,但由于某种原因,需要在dataGrid中保存更改的第二个代码块给了我一个updateCommand错误,我之前提到过,我不明白为什么我在某些表中会出现这个错误,而在其他表中却没有。所以,也许还有其他方法可以保存dataGridView中的更改?因为这是我目前唯一能想到的

我终于找到了Concurrency violation: the UpdateCommand affected 0 of the expected 1 records错误的原因。考虑到我已经在MySql Workbench中创建了我的数据库,并且我试图通过我的应用程序中的dataGridView来使用它,我发现MySql WorkbenchdataGridView中的FLOAT字段之间存在冲突。当您在MySql Workbench中创建一个浮点数时,它应该用一个类似"strong"的点来写;0.1〃,并且在dataGridView中似乎应该用类似于"strong>"的逗号来编写;0,1">因此,一个float字段适用于不同的情况:在mysql Workbench和dataGridView中,有两种不同的编写方法,它会出现错误,正如我所看到的这种情况,当然,我在某些方面可能是错误的,但我只是将所有float字段重新创建为DOUBLE,现在它可以工作了。