This documentation is archived and is not being maintained.

How to: Get Specific Versions of a DataRow 

When changes are made to data rows, the dataset retains both the original (Original) and new (Current) versions of the row. For example, before calling the AcceptChanges method, your application can access the different versions of a record (as defined in the DataRowVersion enumeration) and process the changes accordingly.

NoteNote

Different versions of a row exist only after it has been edited and before it has had the AcceptChanges method called. After the AcceptChanges method has been called, the current and original versions are the same.

Passing the DataRowVersion value along with the column index (or column name as a string) returns the value from that column's particular row version. The changed column is identified during the ColumnChanging and ColumnChanged events, so that is a good time to inspect the differing row versions for validation purposes. However, if you have temporarily suspended constraints, those events will not be raised and you will need to programmatically identify which columns have changed. You can do this by iterating through the Columns collection and comparing the different DataRowVersion values.

Accessing the Original Version of a DataRow

To get the original version of a record

  • Access the value of a column passing in the DataRowVersion of the row you want to return.

    The following example shows how you can use a DataRowVersion value to get the original value of a CompanyName field in a DataRow:

    string originalCompanyName;
    originalCompanyName = northwindDataSet1.Customers[0]
        ["CompanyName", DataRowVersion.Original].ToString();
    
    
    System.String originalCompanyName;
    originalCompanyName = northwindDataSet1.get_Customers().get_Item(0).
        get_Item("CompanyName", DataRowVersion.Original).ToString();
    
    

Accessing the Current Version of a DataRow

To get the current version of a record

  • Access the value of a column and add a parameter to the index indicating which version of a row you want to return.

    The following example shows how you can use a DataRowVersion value to get the current value of a CompanyName field in a DataRow:

    string currentCompanyName;
    currentCompanyName = northwindDataSet1.Customers[0]
        ["CompanyName", DataRowVersion.Current].ToString();
    
    
    System.String currentCompanyName;
    currentCompanyName = northwindDataSet1.get_Customers().get_Item(0).
        get_Item("CompanyName", DataRowVersion.Current).ToString();
    
    

See Also

Show: