有没有人遇到ds.hasChanges()是假的,尽管ds在断点检查时显然有变化?我一直在看它已经有一段时间了,我看不出有什么问题......
// connectionstring and command has been set DataSet ds = new DataSet(); BindingSource myBindingSource = new BindingSource(); SqlDataAdapter dataAdapter1 = new SqlDataAdapter(); dataAdapter1.Fill(ds, "Data"); myBindingSource.DataSource = ds.Tables["Data"]; // then changes made to the datatable on a windows form using bindingnavigator ds.HasChanges(DataRowState.Modified); // is false
现在,当我在使用HasChanges的行之后设置断点并使用DataSet Visualizer时,我可以看到DataSet实际上已经改变,但HasChanges仍然返回false.
我敢肯定我错过了明显的......有人能看出我做错了吗?
干杯
首先尝试在BindingContext上调用EndCurrentEdit():
DataTable dt = ds.Tables["Data"]; this.BindingContext[dt].EndCurrentEdit(); if(ds.HasChanges(DataRowState.Modified)) { // do your stuff here }
同时尝试调用myBindingSource.EndEdit()
它将任何未提交的数据推送到DataTable
.