DataTable.RejectChanges 方法

定义

回滚自该表加载以来或上次调用 AcceptChanges() 以来对该表进行的所有更改。Rolls back all changes that have been made to the table since it was loaded, or the last time AcceptChanges() was called.

public:
 void RejectChanges();
public void RejectChanges ();
member this.RejectChanges : unit -> unit
Public Sub RejectChanges ()

示例

下面的示例对 DataTable进行了几处更改,但通过调用 RejectChanges 方法拒绝更改。The following example makes several changes to a DataTable, but rejects the changes by invoking the RejectChanges method.

private void ShowRejectChanges(DataTable table)
{
    // Print the values of row 1, in the column named "CompanyName."
    Console.WriteLine(table.Rows[1]["CompanyName"]);

    // Make Changes to the column named "CompanyName."
    table.Rows[1]["CompanyName"] = "Taro";

    // Reject the changes.
    table.RejectChanges();

    // Print the original values:
    Console.WriteLine(table.Rows[1]["CompanyName"]);
}
Private Sub ShowRejectChanges(table As DataTable)
    ' Print the values of row 1, in the column named "CompanyName."
    Console.WriteLine(table.Rows(1)("CompanyName"))

    ' Make Changes to the column named "CompanyName."
    table.Rows(1)("CompanyName") = "Taro"

    ' Reject the changes.
    table.RejectChanges()

    ' Print the original values:
    Console.WriteLine(table.Rows(1)("CompanyName"))
End Sub

注解

调用 RejectChanges 时,仍处于编辑模式的任何 DataRow 对象将取消其编辑。When RejectChanges is called, any DataRow objects that are still in edit-mode cancel their edits. 删除新行。New rows are removed. DataRowState 设置为 ModifiedDeleted 返回到其原始状态的行。Rows with the DataRowState set to Modified or Deleted return back to their original state.

适用于

另请参阅