Detecting when a row has changed in a dataset/datatable

14,876

Solution 1

You can use the RowChanged event, the RowChanging event, or any of the other events raised by a DataTable.

Solution 2

To get the original value of an updated Data value you can do this:

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

Solution 3

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.

Share:
14,876
Programatt
Author by

Programatt

I am a programmer by day, and a tinkerer by night.

Updated on June 04, 2022

Comments

  • Programatt
    Programatt almost 2 years

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