DataRowState DataRowState DataRowState DataRowState Enum


获取 DataRow 对象的状态。Gets the state of a DataRow object.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class DataRowState
public enum DataRowState
type DataRowState = 
Public Enum DataRowState


Added Added Added Added 4

该行已添加到 DataRowCollection 中,AcceptChanges() 尚未调用。The row has been added to a DataRowCollection, and AcceptChanges() has not been called.

Deleted Deleted Deleted Deleted 8

该行已通过 Delete()DataRow 方法被删除。The row was deleted using the Delete() method of the DataRow.

Detached Detached Detached Detached 1

已创建该行,但它不是任何 DataRowCollection 的一部分。The row has been created but is not part of any DataRowCollection. DataRow 在以下情况下立即处于此状态:创建之后添加到集合中之前;或从集合中移除之后。A DataRow is in this state immediately after it has been created and before it is added to a collection, or if it has been removed from a collection.

Modified Modified Modified Modified 16

该行已被修改,AcceptChanges() 尚未调用。The row has been modified and AcceptChanges() has not been called.

Unchanged Unchanged Unchanged Unchanged 2

自上一次调用 AcceptChanges() 之后,该行未更改。The row has not changed since AcceptChanges() was last called.


下面的示例首先创建一个新DataTable的, 其中包含一个列, 然后DataRow创建一个。The following example first creates a new DataTable with one column, then creates a single DataRow. 在创建、添加、修改和删除时, 将打印其RowStateDataRowAs the DataRow is created, added, modified, and deleted, its RowState is printed.

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);

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

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

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

   // 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"));
   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))

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

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

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

    ' 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", _
    Return dt
End Function


枚举由类DataRow的属性返回。 RowState DataRowStateThe DataRowState enumeration is returned by the RowState property of the DataRow class.