简体   繁体   中英

Detecting when a row has changed in a dataset/datatable

I'm trying to add some extra logging to my C# winforms application. I have a few data bound forms that all the database stuff is managed by a binding source and some typed datasets/adapters.

With this setup, it's kind of difficult to tell when something is changed, I'd have to manage each field and keep it's previous value. Is there a way I can hook into the dataset and tell when something is changed? I know datarow's have a RowState enumeration, would that be a good place to start? I looked into the binding source's DataMemberChanged event but it never fired so...

要获取更新的数据值的原始值,您可以执行以下操作:

<DataTableRow>[<DataColumn>, DataRowVersion.Original]

To know what has changed look at the DataSet.GetChanges method . The example shows how to get the changes and go through them. I also have an old example here that uses a DataTable and shows how to do a comparison after a merge. It inspects the RowState and shows the changed values etc. It's near the bottom of the page and it's in VB since the OP was using that, not C#. I'm headed out now so I can't provide an equivalent translation but it should be pretty straightforward to glean some useful techniques from.

您可以使用RowChanged事件, RowChanging事件或DataTable引发的任何其他事件

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM