DataRow.RowState 属性
获取与该行和 DataRowCollection 的关系相关的当前状态。
**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)
语法
声明
Public ReadOnly Property RowState As DataRowState
用法
Dim instance As DataRow
Dim value As DataRowState
value = instance.RowState
public DataRowState RowState { get; }
public:
property DataRowState RowState {
DataRowState get ();
}
/** @property */
public DataRowState get_RowState ()
public function get RowState () : DataRowState
属性值
DataRowState 值之一。
备注
RowState 的值取决于两个因素:(1) 已在行上执行的操作类型;(2) 是否已对 DataRow 调用了 AcceptChanges。
示例
下面的示例首先创建有一个列的新 DataTable,然后创建单个 DataRow。当创建、添加、修改和删除 DataRow 时,将输出其 RowState。
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 DataTable = New DataTable("table")
Dim dcFirstName As DataColumn = New DataColumn( _
"FirstName", Type.GetType("System.String"))
table.Columns.Add(dcFirstName)
MakeTable = table
End Function
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;
}
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
.NET Compact Framework
受以下版本支持:2.0、1.0
请参见
参考
DataRow 类
DataRow 成员
System.Data 命名空间
AcceptChanges
BeginEdit
Add
CancelEdit
DataTable
DataRowView
Delete
EndEdit
NewRow