.NET DataSet.HasChanges 错误地为 false
有没有人遇到过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先尝试调用 BindingContext 上的 EndCurrentEdit():
另外尝试调用
myBindingSource.EndEdit()
,将所有未提交的数据推送到DataTable
。Try calling the EndCurrentEdit() on BindingContext first:
Also try calling the
myBindingSource.EndEdit()
that will push any un-commited data to theDataTable
.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?