DataSet.HasChanges Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets a value indicating whether the DataSet has changes, including new, deleted, or modified rows.

Namespace:   System.Data
Assembly:  System.Data (in System.Data.dll)

public bool HasChanges()

Return Value

Type: System.Boolean

true if the DataSet has changes; otherwise false.

The following example uses the GetChanges method to create a second DataSet object that is then used to update a data source.

private void UpdateDataSet(DataSet dataSet)
    // Check for changes with the HasChanges method first.
    if(!dataSet.HasChanges()) return;

    // Create temporary DataSet variable.
    DataSet tempDataSet;

    // GetChanges for modified rows only.
    tempDataSet = dataSet.GetChanges(DataRowState.Modified);

    // Check the DataSet for errors.
        // Insert code to resolve errors.
    // After fixing errors, update the data source with 
    // the DataAdapter used to create the DataSet.

.NET Framework
Available since 1.1
Return to top