How to: Retrieve Changed Rows
Each row in a data table has a RowState property that keeps track of the current state of that row using the values in the DataRowState enumeration. You can return changed rows from a dataset or data table by calling the GetChanges method of a DataSet or DataTable. You can verify changes exist prior to calling GetChanges by calling the HasChanges method of a dataset. For more information on HasChanges, see How to: Check for Changed Rows.
After you commit changes to a dataset or data table (by calling the AcceptChanges method), the GetChanges method will return no data. If your application needs to process changed rows, you must do so before calling the AcceptChanges method.
Calling the GetChanges method of a dataset or data table returns a new dataset or data table that contains only records that have been changed. If you want to get only specific records — for example, only new records or only modified records — you can pass a value from the DataRowState enumeration as a parameter to the GetChanges method.
Use the DataRowVersion enumeration to access the different versions of a row (for example, you might want to examine the original values in a row prior to processing it.
To get all changed records from a dataset
Call the GetChanges method of a dataset.
The following example creates a new dataset called changedRecords and populates it with all the changed records from another dataset called dataSet1.
To get all changed records from a data table
Call the GetChanges method of a DataTable.
The following example creates a new data table called changedRecordsTable and populates it with all the changed records from another data table called dataTable1.
To get all records that have a specific row state
Call the GetChanges method of a dataset or data table and pass a DataRowState enumeration value as an argument.
The following example shows how to create a new dataset called addedRecords and populate it only with records that have been added to the dataSet1 dataset.
The following example shows how to return all records recently added to the Customers table: