两端代码,其中:
            foreach (DataGridViewRow r in dataGridView1.SelectedRows)
            {
                dataGridView1.Rows.RemoveAt(r.Index);
            }
            res_info_Adapter.Update(datatable);
能成功删除数据库中的记录

            foreach (DataGridViewRow r in dataGridView1.SelectedRows)
            {
                datatable.Rows.RemoveAt(r.Index);
            }
            res_info_Adapter.Update(datatable);
就无法成功删除数据库中的记录,然而也不报错,这是为什么啊?其中 
this.cb_res_info = System.Data.OleDb.OleDbFactory.Instance.CreateCommandBuilder();
res_info_Adapter = new System.Data.OleDb.OleDbDataAdapter(sql_res_info_Adapter, ConnectStr);
res_info_Adapter.MissingSchemaAction = System.Data.MissingSchemaAction.AddWithKey;
cb_res_info.DataAdapter = res_info_Adapter;
res_info_Adapter.InsertCommand = (System.Data.OleDb.OleDbCommand)cb_res_info.GetInsertCommand();
res_info_Adapter.DeleteCommand = (System.Data.OleDb.OleDbCommand)cb_res_info.GetDeleteCommand();
res_info_Adapter.UpdateCommand = (System.Data.OleDb.OleDbCommand)cb_res_info.GetUpdateCommand();datatable = new System.Data.DataTable();
this.res_info_Adapter.Fill(datatable);
dataGridView1.DataSource = datatable;

解决方案 »

  1.   

    你的绑定已经具体到某一个表了,而DataGridview里面是有很多表的,它没有提示错误是因为你的里面只有一个表,它已经默认了!
      

  2.   

    大哥…… 没看明白你这句话的意思~~~
    dataGridView1.DataSource   =   datatable;   
    datatable是一个表,
    那么dataGridView1 就只能是绑定到这一个表吧?
    即使
    dataGridView1.DataSource   =   datatable1;
    dataGridView1.DataSource   =   datatable2;
    也是后一个生效把?
    我就是很奇怪为啥dataGridView1.Rows.RemoveAt(r.Index); 能生效而datatable.Rows.RemoveAt(r.Index); 不生效呢?