DataTable.RejectChanges DataTable.RejectChanges DataTable.RejectChanges DataTable.RejectChanges Method

定义

回滚自该表加载以来或上次调用 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. 设置为ModifiedDeleted返回到其原始状态的行。 DataRowStateRows with the DataRowState set to Modified or Deleted return back to their original state.

适用于

另请参阅