DataRow.AcceptChanges 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提交自上次调用 AcceptChanges() 以来对该行进行的所有更改。
public:
void AcceptChanges();
public void AcceptChanges ();
member this.AcceptChanges : unit -> unit
Public Sub AcceptChanges ()
例外
此行不属于该表。
示例
以下示例首先创建一个包含一列的新 DataTable ,然后创建单个 DataRow。 DataRow创建、添加、修改和删除 时,将打印其 RowState 。
private void DemonstrateAcceptChanges()
{
//Run a function to create a DataTable with one column.
DataTable table = MakeTable();
DataRow row;
// Create a new DataRow.
row = table.NewRow();
// Detached row.
Console.WriteLine("New Row " + row.RowState);
table.Rows.Add(row);
// New row.
Console.WriteLine("AddRow " + row.RowState);
table.AcceptChanges();
// Unchanged row.
Console.WriteLine("AcceptChanges " + row.RowState);
row["FirstName"] = "Scott";
// Modified row.
Console.WriteLine("Modified " + row.RowState);
row.Delete();
// Deleted row.
Console.WriteLine("Deleted " + row.RowState);
}
private DataTable MakeTable()
{
// Make a simple table with one column.
DataTable table = new DataTable("table");
DataColumn fnameColumn = new DataColumn(
"FirstName", Type.GetType("System.String"));
table.Columns.Add(fnameColumn);
return table;
}
Private Sub DemonstrateAcceptChanges()
' Run a function to create a DataTable with one column.
Dim table As DataTable = MakeTable()
Dim row As DataRow
' Create a new DataRow.
row = table.NewRow()
' Detached row.
Console.WriteLine("New Row " & row.RowState)
table.Rows.Add(row)
' New row.
Console.WriteLine("AddRow " & row.RowState)
table.AcceptChanges()
' Unchanged row.
Console.WriteLine("AcceptChanges " & row.RowState)
row("FirstName") = "Scott"
' Modified row.
Console.WriteLine("Modified " & row.RowState)
row.Delete()
' Deleted row.
Console.WriteLine("Deleted " & row.RowState)
End Sub
Private Function MakeTable()As DataTable
' Make a simple table with one column.
Dim table As New DataTable("table")
Dim fnameColumn As New DataColumn( _
"FirstName", Type.GetType("System.String"))
table.Columns.Add(fnameColumn)
MakeTable = table
End Function
注解
调用 AcceptChanges时, EndEdit 将隐式调用 方法以结束任何编辑。 RowState如果行的 已添加或修改,则 RowState 变为未更改。 RowState如果 为 Deleted,则删除该行。
有关更多信息,请参阅 BeginEdit 方法。
类 DataTable 还具有影响 AcceptChanges 对整个表所做的更改的方法。 有关详细信息以及演示如何接受和拒绝对单个数据行所做的更改的代码示例,请参阅 AcceptChanges 和 RejectChanges。