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. 設定為DataRowState Modified或回到其原始狀態的資料列。DeletedRows with the DataRowState set to Modified or Deleted return back to their original state.

適用於

另請參閱