Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

DataSet.HasChanges Method

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

Overload List

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function HasChanges() As Boolean
[C#] public bool HasChanges();
[C++] public: bool HasChanges();
[JScript] public function HasChanges() : Boolean;

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

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Function HasChanges(DataRowState) As Boolean
[C#] public bool HasChanges(DataRowState);
[C++] public: bool HasChanges(DataRowState);
[JScript] public function HasChanges(DataRowState) : Boolean;

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, C#, C++] Note   This example shows how to use one of the overloaded versions of HasChanges. For other examples that might be available, see the individual overload topics.
[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.

See Also

DataSet Class | DataSet Members | System.Data Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.