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 ()

示例

下面的示例演示一个派生自 DataSet 类的类。The 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,对 DataSet中包含的所有 DataTable 对象调用 DataTable.RejectChanges 方法。Invoke the DataSet.RejectChanges to call the DataTable.RejectChanges method on all DataTable objects contained by the DataSet.

通过调用 DataRow.BeginEdit 方法,每个 DataRow DataSet 包含的对象都可以设置为编辑模式。DataRow objects contained by the DataSet can each be set into edit mode by invoking the DataRow.BeginEdit method. 调用 DataRow.EndEdit 方法后,可以通过对 DataRow 对象所属的 DataTable 调用 DataTable.RejectChanges 来拒绝更改。After 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 相关的更改(即 AddRemoveDeleteModify)。AcceptChanges and RejectChanges only apply to DataRow related changes (that is, Add, Remove, Delete, and Modify). 它们不适用于架构或结构更改。They are not applicable to schema or structural changes.

适用于

另请参阅