GetChanges () or RowState to get all changes in datatable?

In a Winforms application , I have to log all changes to the datagrid (datatable) . In other words, I want to get all the changes since it was downloaded. For this, I want to use Datatable.GetChanges () . I know that with GetChanges () I get a datatable containing a copy of all the rows in the original DataSet that have pending changes.

Now my question is if additional additional information about the changes can also be obtained . For example, I want to know whether the line is added or removed , or has only been updated . If the row was updated , I also want to know which cells have been updated? Is there a way to get all this information quickly or do I need to do a deep row-by-row comparison with the original datatable ?

Or is it better to use RowState to get all the changes?

+5
source share
2 answers

To verify the addition / removal of a row RowState

( ) DataRowVersion

        foreach (DataRow dr in dt.Rows)
        {
            if (dr.RowState == DataRowState.Modified)
            {
                var changedCols = new List<DataColumn>();
                foreach (DataColumn dc in dt.Columns)
                {
                    if (!dr[dc, DataRowVersion.Original].Equals(
                         dr[dc, DataRowVersion.Current])) /* skipped Proposed as indicated by a commenter */
                    {
                        changedCols.Add(dc);
                    }
                }
                // now handle the changedCols list
            }
        }
+8

DataRow DataTable RowState, , ​​, .

, , .

+2

All Articles