共用方式為


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

資料列已建立,但它不屬於任何 DataRowCollectionDataRow 在已經建立後、加入至集合前,或如果已經從集合移除後,會立即處在這個狀態中。

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是由 類別的 DataRow 屬性傳RowState回。

適用於

另請參閱