DataRow.RowState 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得關於資料列與 DataRowCollection 之關聯性 (Relationship) 的資料列目前狀態。
public:
property System::Data::DataRowState RowState { System::Data::DataRowState get(); };
public System.Data.DataRowState RowState { get; }
member this.RowState : System.Data.DataRowState
Public ReadOnly Property RowState As DataRowState
屬性值
其中一個 DataRowState 值。
範例
下列範例會先使用一個資料列建立新的 DataTable ,然後建立單 DataRow一 。 DataRow建立、新增、修改和刪除時,會列印其 RowState 。
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;
}
Private Sub DemonstrateRowState()
' Run a function to create a DataTable with one column.
Dim table As DataTable = MakeTable()
Dim row As DataRow
' 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)
End Sub
Private Function MakeTable() As DataTable
' Make a simple table with one column.
Dim table As New DataTable("table")
Dim dcFirstName As New DataColumn( _
"FirstName", Type.GetType("System.String"))
table.Columns.Add(dcFirstName)
MakeTable = table
End Function
備註
的值 RowState 取決於兩個因素:已在資料列上執行作業類型,以及是否已 AcceptChanges 在 上 DataRow呼叫 。