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

資料列已建立,但它不屬於任何 DataRowCollectionThe 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. 當建立、新增、修改和刪除RowState 時,會列印其。DataRowAs 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.