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设置为 Modified
或 Deleted
返回到其原始状态的行。Rows with the DataRowState set to Modified
or Deleted
return back to their original state.