ds.Rows.RemoveAt(this.BindingContext[ds].Position);(该行删除成功,在画面上)
//保存代码
public void save_data()
{
DataTable bb = new DataTable();
this.BindingContext[ds].EndCurrentEdit();
bb = ds.GetChanges();
if (bb!=null)
{
if (MessageBox.Show(this,"您修改过数据确定要修改吗?","注意",MessageBoxButtons.YesNo,MessageBoxIcon.Error) == DialogResult.Yes)
{ OleDbCommandBuilder cc =new OleDbCommandBuilder(da);
da.Update(ds);
ds.AcceptChanges();
}
else
{
ds.RejectChanges();
}
}
//保存代码
public void save_data()
{
DataTable bb = new DataTable();
this.BindingContext[ds].EndCurrentEdit();
bb = ds.GetChanges();
if (bb!=null)
{
if (MessageBox.Show(this,"您修改过数据确定要修改吗?","注意",MessageBoxButtons.YesNo,MessageBoxIcon.Error) == DialogResult.Yes)
{ OleDbCommandBuilder cc =new OleDbCommandBuilder(da);
da.Update(ds);
ds.AcceptChanges();
}
else
{
ds.RejectChanges();
}
}
你用ds.Rows.RemoveAt()把Row直接删除了,而不是用Delete()方法的话
ds所有的DataRow的RowStatus全部是未改动状态,GetChange()当然返回nullRemoveAt()方法是删除DataRow对象,而不是删除数据库的行.(应使用Delete()方法)
ds.Rows.RemoveAt(this.BindingContext[ds].Position);(该行删除成功,在画面上)
//改为
ds.Rows[this.BindingContext[ds].Position].Delete();
ds.Rows.RemoveAt(this.BindingContext[ds].Position);(该行删除成功,在画面上)
前面加上下面一句试试..ds.AcceptChanges();