DataRowState 枚举

定义

获取 DataRow 对象的状态。

此枚举支持其成员值的按位组合。

public enum class DataRowState
[System.Flags]
public enum DataRowState
[<System.Flags>]
type DataRowState = 
Public Enum DataRowState
继承
DataRowState
属性

字段

Added 4

该行已添加到 DataRowCollection 中,AcceptChanges() 尚未调用。

Deleted 8

该行已通过 Delete()DataRow 方法被删除。

Detached 1

已创建该行,但它不是任何 DataRowCollection 的一部分。 DataRow 在以下情况下立即处于此状态:创建之后添加到集合中之前;或从集合中移除之后。

Modified 16

该行已被修改,AcceptChanges() 尚未调用。

Unchanged 2

自上一次调用 AcceptChanges() 之后,该行未更改。

示例

以下示例首先创建一个包含一列的新 DataTable ,然后创建一 DataRow个 。 DataRow创建、添加、修改和删除 时,将打印其 RowState

private void DemonstrateRowState() {
   //Run a function to create a DataTable with one column.
   DataTable myTable = MakeTable();
   DataRow myRow;

   // Create a new DataRow.
   myRow = myTable.NewRow();
   // Detached row.
   Console.WriteLine("New Row " + myRow.RowState);

   myTable.Rows.Add(myRow);
   // New row.
   Console.WriteLine("AddRow " + myRow.RowState);

   myTable.AcceptChanges();
   // Unchanged row.
   Console.WriteLine("AcceptChanges " + myRow.RowState);

   myRow["FirstName"] = "Scott";
   // Modified row.
   Console.WriteLine("Modified " + myRow.RowState);

   myRow.Delete();
   // Deleted row.
   Console.WriteLine("Deleted " + myRow.RowState);
}

private DataTable MakeTable(){
   // Make a simple table with one column.
   DataTable dt = new DataTable("myTable");
   DataColumn dcFirstName = new DataColumn("FirstName", Type.GetType("System.String"));
   dt.Columns.Add(dcFirstName);
   return dt;
}
Private Sub DemonstrateRowState()
    'Run a function to create a DataTable with one column.
    Dim dataTable As DataTable = MakeTable()
    Dim dataRow As DataRow

    ' Create a new DataRow.
    dataRow = dataTable.NewRow()
    ' Detached row.
    Console.WriteLine(String.Format("New Row {0}", dataRow.RowState))

    dataTable.Rows.Add(dataRow)
    ' New row.
    Console.WriteLine(String.Format("AddRow {0}", dataRow.RowState))

    dataTable.AcceptChanges()
    ' Unchanged row.
    Console.WriteLine(String.Format("AcceptChanges {0}", dataRow.RowState))

    dataRow("FirstName") = "Scott"
    ' Modified row.
    Console.WriteLine(String.Format("Modified {0}", dataRow.RowState))

    dataRow.Delete()
    ' Deleted row.
    Console.WriteLine(String.Format("Deleted {0}", dataRow.RowState))
End Sub

Private Function MakeTable() As DataTable
    ' Make a simple table with one column.
    Dim dt As New DataTable("dataTable")
    Dim firstName As New DataColumn("FirstName", _
       Type.GetType("System.String"))
    dt.Columns.Add(firstName)
    Return dt
End Function

注解

DataRowState枚举由 RowState 类的 DataRow 属性返回。

适用于

另请参阅