DataTable.RejectChanges Method
Rolls back all changes that have been made to the table since it was loaded, or the last time AcceptChanges was called.
[Visual Basic] Public Sub RejectChanges() [C#] public void RejectChanges(); [C++] public: void RejectChanges(); [JScript] public function RejectChanges();
Remarks
When RejectChanges is called, any DataRow objects that are still in edit-mode cancel their edits. New rows are removed. Rows with the DataRowState set to Modified or Deleted return back to their original state.
Example
[Visual Basic, C#, C++] The following example makes several changes to a DataTable, but rejects the changes by invoking the RejectChanges method.
[Visual Basic] Private Sub ShowRejectChanges(myTable As DataTable) ' Print the values of row 1, in the column named "CompanyName." Console.WriteLine(myTable.Rows(1)("CompanyName")) ' Make Changes to the column named "CompanyName." myTable.Rows(1)("CompanyName") = "Taro" ' Reject the changes. myTable.RejectChanges() ' Print the original values: Console.WriteLine(myTable.Rows(1)("CompanyName")) End Sub [C#] private void ShowRejectChanges(DataTable myTable){ // Print the values of row 1, in the column named "CompanyName." Console.WriteLine(myTable.Rows[1]["CompanyName"]); // Make Changes to the column named "CompanyName." myTable.Rows[1]["CompanyName"] = "Taro"; // Reject the changes. myTable.RejectChanges(); // Print the original values: Console.WriteLine(myTable.Rows[1]["CompanyName"]); } [C++] private: void ShowRejectChanges(DataTable* myTable){ // Print the values of row 1, in the column named "CompanyName." Console::WriteLine(myTable->Rows->Item[1]->Item[S"CompanyName"]); // Make Changes to the column named "CompanyName." myTable->Rows->Item[1]->Item[S"CompanyName"] = S"Taro"; // Reject the changes. myTable->RejectChanges(); // Print the original values: Console::WriteLine(myTable->Rows->Item[1]->Item[S"CompanyName"]); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
See Also
DataTable Class | DataTable Members | System.Data Namespace | AcceptChanges | BeginEdit | DataRow | DataRowState | DataRowVersion | EndEdit