Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
GetChanges Method (DataRowState)
Collapse the table of content
Expand the table of content

DataSet.GetChanges Method (DataRowState)

.NET Framework 1.1

Gets a copy of the DataSet containing all changes made to it since it was last loaded, or since AcceptChanges was called, filtered by DataRowState.

[Visual Basic]
Overloads Public Function GetChanges( _
   ByVal rowStates As DataRowState _
) As DataSet
[C#]
public DataSet GetChanges(
 DataRowState rowStates
);
[C++]
public: DataSet* GetChanges(
 DataRowState rowStates
);
[JScript]
public function GetChanges(
   rowStates : DataRowState
) : DataSet;

Parameters

rowStates
One of the DataRowState values.

Return Value

A filtered copy of the DataSet that can have actions performed on it, and subsequently be merged back in using Merge. If no rows of the desired DataRowState are found, the method returns a null reference (Nothing in Visual Basic).

Remarks

The GetChanges method is used to produce a second DataSet object which contains only the changes introduced into the original. Use the rowStates argument to specify the type of changes the new object should include.

This returned copy is designed to be merged back in to this original DataSet. Relationship constraints may cause parent rows marked Unchanged to be included. If no rows of the desired DataRowState are found, the GetChanges method returns a null reference (Nothing in Visual Basic).

Example

[Visual Basic, C#, C++] The following example uses the GetChanges method to create a second DataSet object that is then used to update a data source.

[Visual Basic] 
Private Sub UpdateDataSet(ByVal myDataSet As DataSet)
   ' Check for changes with the HasChanges method first.
   If Not myDataSet.HasChanges(DataRowState.Modified) Then Exit Sub
   ' Create temporary DataSet variable.
   Dim xDataSet As DataSet
   ' GetChanges for modified rows only.
   xDataSet = myDataSet.GetChanges(DataRowState.Modified)
   ' Check the DataSet for errors.
   If xDataSet.HasErrors Then
      ' Insert code to resolve errors.
   End If
   ' After fixing errors, update the data source with the DataAdapter 
   ' used to create the DataSet.
   myOleDbDataAdapter.Update(xDataSet)
End Sub

[C#] 
private void UpdateDataSet(DataSet myDataSet){
   // Check for changes with the HasChanges method first.
   if(!myDataSet.HasChanges(DataRowState.Modified)) return;
   // Create temporary DataSet variable.
   DataSet xDataSet;
   // GetChanges for modified rows only.
   xDataSet = myDataSet.GetChanges(DataRowState.Modified);
   // Check the DataSet for errors.
   if(xDataSet.HasErrors){
      // Insert code to resolve errors.
   }
   // After fixing errors, update the data source with the DataAdapter 
   // used to create the DataSet.
   myOleDbDataAdapter.Update(xDataSet);
}

[C++] 
private:
 void UpdateDataSet(DataSet* myDataSet){
    // Check for changes with the HasChanges method first.
    if(!myDataSet->HasChanges(DataRowState::Modified)) return;
    // Create temporary DataSet variable.
    DataSet* xDataSet;
    // GetChanges for modified rows only.
    xDataSet = myDataSet->GetChanges(DataRowState::Modified);
    // Check the DataSet for errors.
    if(xDataSet->HasErrors){
       // Insert code to resolve errors.
    }
    // After fixing errors, update the data source with the DataAdapter 
    // used to create the DataSet.
    myOleDbDataAdapter->Update(xDataSet);
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataSet Class | DataSet Members | System.Data Namespace | DataSet.GetChanges Overload List | GetChanges

Show:
© 2015 Microsoft