.NET DataSet.HasChanges 错误地为 false

发布于 2024-07-27 12:02:53 字数 663 浏览 10 评论 0原文

有没有人遇到过 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。

我确信我错过了显而易见的事情......有人能看到我做错了什么吗?

干杯

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚笙 2024-08-03 12:02:54

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

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

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

另外尝试调用 myBindingSource.EndEdit() ,将所有未提交的数据推送到 DataTable

Try calling the EndCurrentEdit() on BindingContext first:

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

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

Also try calling the myBindingSource.EndEdit() that will push any un-commited data to the DataTable.

如歌彻婉言 2024-08-03 12:02:54

Windows 窗体没有对数据集执行 .AcceptChanges() 调用,是吗?

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

The Windows Form isn't doing a .AcceptChanges() call on the DataSet is it?

Edit:
Ok so not that. Next things, per my comment:
1) have records def been modified and not just added/deleted? What does DataSet.HasChanges() return?
2) what does GetChanges() return for the specific datable within the dataset?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文