DataSet.RejectChanges 方法

定义

回滚自创建 DataSet 以来或上次调用 AcceptChanges() 以来对其进行的所有更改。Rolls back all the changes made to the DataSet since it was created, or since the last time AcceptChanges() was called.

public:
 virtual void RejectChanges();
public virtual void RejectChanges ();
abstract member RejectChanges : unit -> unit
override this.RejectChanges : unit -> unit
Public Overridable Sub RejectChanges ()

示例

下面的示例演示一个派生自类的类 DataSetThe following example shows a class derived from the DataSet class. RejectChanges从函数内部调用事件。The RejectChanges event is invoked from within a function.

private void RejectChangesInDataSet()
{
    // Instantiate the derived DataSet.
    DerivedDataSet derivedData = new DerivedDataSet();

    // Insert code to change values.

    // Invoke the RejectChanges method in the derived class.
    derivedData.RejectDataSetChanges();
}

public  class DerivedDataSet:System.Data.DataSet
{
    public void RejectDataSetChanges()
    {
        // Invoke the RejectChanges method.
        this.RejectChanges();
    }
}
Private Sub RejectChangesInDataSet()
    ' Instantiate the derived DataSet.
    Dim derivedData As DerivedDataSet
    derivedData = New DerivedDataSet()

   ' Insert code to change values.

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

注解

调用以对所 DataSet.RejectChanges DataTable.RejectChanges 包含的所有对象调用方法 DataTable DataSetInvoke the DataSet.RejectChanges to call the DataTable.RejectChanges method on all DataTable objects contained by the DataSet.

DataRow 中包含的对象 DataSet 可通过调用方法设置为编辑模式 DataRow.BeginEditDataRow objects contained by the DataSet can each be set into edit mode by invoking the DataRow.BeginEdit method. 调用方法后 DataRow.EndEdit ,可以通过 DataTable.RejectChangesDataTable 对象所属的上调用来拒绝更改 DataRowAfter invoking the DataRow.EndEdit method, changes can be rejected by calling the DataTable.RejectChanges on the DataTable to which the DataRow objects belong.

DataTable.RejectChanges调用方法时,仍处于编辑模式的任何行都将取消其编辑。When the DataTable.RejectChanges method is called, any rows still in edit-mode cancel their edits. 删除新行。New rows are removed. 修改和删除的行返回到其原始状态 (DataRowState.Unchanged) 。Modified and deleted rows return back to their original state (DataRowState.Unchanged).

AcceptChanges 和 RejectChanges 仅适用于 DataRow 、、、 Add Remove Delete 和) (的相关更改 ModifyAcceptChanges and RejectChanges only apply to DataRow related changes (that is, Add, Remove, Delete, and Modify). 它们不适用于架构或结构更改。They are not applicable to schema or structural changes.

适用于

另请参阅