ado.net数据集中的脏记录 [英] ado.net dirty records in dataset
问题描述
我会尝试解释。
我想跟踪绑定到窗口(wpf)控件上的数据集行中的脏记录。
I'll try to explain. I want to track dirty records in my dataset row that is bound to controls on window (wpf).
效果很好。可以说我开始编辑绑定到该dataSet中的dataTable的一些文本框。在我向文本框中添加一个字符后,数据集被标记为肮脏。
It works fine. Lets say i begin to edit some textbox that is bound to dataTable in that dataSet. After i add one character to textbox, dataset is marked dirty.
但是如果我再次删除该字符(恢复原始值),则数据集仍然是肮脏的。在将原始值恢复为dataSet之后,我想要的
不会变脏,因为实际上它不再变脏。
But if I delete that character again ( restore original value ), dataset is still dirty. I want after i restore original value to dataSet become not dirty, because in reallity it isn't dirty any more.
我是否需要任何方法调用,以便数据集可以从绑定字段或某些类似方法中重新计算脏记录。谢谢。
Is there any method i need to call so dataset can recompute dirty records from binding fields, or some similar aproach. Thanks.
推荐答案
好吧,有什么工作要做,只是想分享。到目前为止,一切都很好。谢谢大家的回答,对我有很大帮助。下一步是将此功能构建到自定义控件中:)。
Well, got something working, just wanted to share. So far so good. Thanks everyone for answers, helped me alot. Next step is building this functionality into custom control :).
private bool dirty = false;
private int currentRowIndex;
void Products_RowChanged(object sender, System.Data.DataRowChangeEventArgs e)
{
currentRowIndex=ProductsViewSource.View.CurrentPosition;
int i=0;
foreach (object o in originalProducts[currentRowIndex].ItemArray)
{
if (o.Equals(restouranDataSet.Products[currentRowIndex].ItemArray[i]))
dirty = false;
else
{
dirty = true;
return;
}
i++;
}
}
这篇关于ado.net数据集中的脏记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!