DataRow.RowState 属性

时间:2023-03-09 15:37:31
DataRow.RowState 属性

RowState 的值取决于两个因素:已对该行执行的操作的类型,以及是否已对 DataRow 调用了 AcceptChanges。

private void DemonstrateRowState()
{
// 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 dcFirstName = new DataColumn(
"FirstName", Type.GetType("System.String"));
table.Columns.Add(dcFirstName);
return table;
}