3

Has anybody come across ds.hasChanges() being false despite that the ds clearly has the changes while you check it at a breakpoint? I've been looking at it for quite a while and I can't see what is wrong...

// 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

Now when I set a breakpoint after the row with HasChanges and use DataSet Visualizer I can see that the DataSet has in fact changed, but HasChanges still returns false.

I'm sure I'm missing the obvious... can anybody see what I'm doing wrong?

Cheers

4

2 回答 2

9

首先尝试在 BindingContext 上调用 EndCurrentEdit():

DataTable dt = ds.Tables["Data"];
this.BindingContext[dt].EndCurrentEdit();

if(ds.HasChanges(DataRowState.Modified))
{
  // do your stuff here
}

还可以尝试调用myBindingSource.EndEdit()将任何未提交的数据推送到DataTable.

于 2009-07-22T14:24:03.153 回答
0

Windows 窗体没有对 DataSet 进行 .AcceptChanges() 调用,是吗?

编辑: 好的,不是那样的。接下来的事情,根据我的评论:
1)记录def是否被修改而不仅仅是添加/删除?DataSet.HasChanges() 返回什么?
2) GetChanges() 为数据集中的特定数据返回什么?

于 2009-07-22T14:05:16.207 回答