Partager via


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.

Note

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:

    Dim originalCompanyName = NorthwindDataSet1.Customers(0)(
       "CompanyName", DataRowVersion.Original).ToString()
    
    string originalCompanyName;
    originalCompanyName = northwindDataSet1.Customers[0]
        ["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:

    Dim currentCompanyName = NorthwindDataSet1.Customers(0)(
        "CompanyName", DataRowVersion.Current).ToString()
    
    string currentCompanyName;
    currentCompanyName = northwindDataSet1.Customers[0]
        ["CompanyName", DataRowVersion.Current].ToString();
    

See Also

Concepts

Editing Data in Your Application

Validating Data

Saving Data

Binding Windows Forms Controls to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Binding Controls to Data in Visual Studio

Other Resources

Data Walkthroughs

Overview of Data Applications in Visual Studio

Connecting to Data in Visual Studio