Export (0) Print
Expand All

DataSet.RejectChanges Method

Rolls back all the changes made to the DataSet since it was created, or since the last time DataSet.AcceptChanges was called.

[Visual Basic]
Public Overridable Sub RejectChanges()
[C#]
public virtual void RejectChanges();
[C++]
public: virtual void RejectChanges();
[JScript]
public function RejectChanges();

Remarks

Invoke the DataSet.RejectChanges to call the DataTable.RejectChanges method on all DataTable objects contained by the DataSet.

DataRow objects contained by the DataSet can each be set into edit mode by invoking the DataRow.BeginEdit method. After invoking the DataRow.EndEdit method, changes can be rejected by calling the DataTable.RejectChanges on the DataTable to which the DataRow objects belong.

When the DataTable.RejectChanges method is called, any rows still in edit-mode cancel their edits. New rows are removed. Modified and deleted rows return back to their original state (DataRowState.Unchanged).

Example

[Visual Basic, C#, C++] The following example shows a class derived from the DataSet class. The RejectChanges event invoked from within a function.

[Visual Basic] 
Private Sub RejectChangesInDataSet()
    ' Instantiate the derived DataSet.
    Dim myDerivedDataSet As DerivedDataSet
    myDerivedDataSet = New DerivedDataSet()

   ' Insert code to change values.

   ' Invoke the RejectChanges method in the derived class.
   myDerivedDataSet.RejectDataSetChanges()
End Sub
   
' +++++++++++++++++++++++++++++++++++++++++++++++
Public Class DerivedDataSet
    Inherits System.Data.DataSet
     
    Public Sub RejectDataSetChanges()
        ' Invoke the RejectChanges method.
        Me.RejectChanges()
    End Sub
 End Class

[C#] 
private void RejectChangesInDataSet(){
   // Instantiate the derived DataSet.
   DerivedDataSet myDerivedDataSet = new DerivedDataSet();
   // Insert code to change values.
   
   // Invoke the RejectChanges method in the derived class.
   myDerivedDataSet.RejectDataSetChanges();
}

// +++++++++++++++++++++++++++++++++++++++++++++++
public  class DerivedDataSet:System.Data.DataSet {
   public void RejectDataSetChanges(){
      // Invoke the RejectChanges method.
      this.RejectChanges();
   }
}

[C++] 
private:
 void RejectChangesInDataSet(){
    // Instantiate the derived DataSet.
    DerivedDataSet* myDerivedDataSet = new DerivedDataSet();
    // Insert code to change values.
    
    // Invoke the RejectChanges method in the derived class.
    myDerivedDataSet->RejectDataSetChanges();
 }

 // +++++++++++++++++++++++++++++++++++++++++++++++
public:
 __gc class DerivedDataSet:public System::Data::DataSet {
public:
    void RejectDataSetChanges(){
       // Invoke the RejectChanges method.
       this->RejectChanges();
    }
 };

[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, .NET Compact Framework

See Also

DataSet Class | DataSet Members | System.Data Namespace | AcceptChanges

Show:
© 2014 Microsoft