DataRowVersion 枚举
定义
public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion =
Public Enum DataRowVersion
- 继承
字段
Current | 512 | 包含其当前值的行。The row contains current values. |
Default | 1536 | DataRowState 的默认版本。The default version of DataRowState. 对于 |
Original | 256 | 包含其原始值的行。The row contains its original values. |
Proposed | 1024 | 包含建议值的行。The row contains a proposed value. |
示例
下面的示例在 DataRowVersion DataRow 调用方法之前检查的 AcceptChanges 。The following example checks the DataRowVersion of a DataRow before invoking the AcceptChanges method.
private static void CheckVersionBeforeAccept()
{
//Run a function to create a DataTable with one column.
DataTable dataTable = MakeTable();
DataRow dataRow = dataTable.NewRow();
dataRow["FirstName"] = "Marcy";
dataTable.Rows.Add(dataRow);
dataRow.BeginEdit();
// Edit data but keep the same value.
dataRow[0] = "Marcy";
// Uncomment the following line to add a new value.
// dataRow(0) = "Richard"
Console.WriteLine(string.Format("FirstName {0}", dataRow[0]));
// Compare the proposed version with the current.
if (dataRow.HasVersion(DataRowVersion.Proposed)) {
if (object.ReferenceEquals(dataRow[0, DataRowVersion.Current], dataRow[0, DataRowVersion.Proposed])) {
Console.WriteLine("The original and the proposed are the same.");
dataRow.CancelEdit();
} else {
dataRow.AcceptChanges();
Console.WriteLine("The original and the proposed are different.");
}
}
}
private static DataTable MakeTable()
{
// Make a simple table with one column.
DataTable dt = new DataTable("dataTable");
DataColumn firstName = new DataColumn("FirstName", Type.GetType("System.String"));
dt.Columns.Add(firstName);
return dt;
}
Private Sub CheckVersionBeforeAccept()
'Run a function to create a DataTable with one column.
Dim dataTable As DataTable = MakeTable()
Dim dataRow As DataRow = dataTable.NewRow()
dataRow("FirstName") = "Marcy"
dataTable.Rows.Add(dataRow)
dataRow.BeginEdit()
' Edit data but keep the same value.
dataRow(0) = "Marcy"
' Uncomment the following line to add a new value.
' dataRow(0) = "Richard"
Console.WriteLine(String.Format("FirstName {0}", dataRow(0)))
' Compare the proposed version with the current.
If dataRow.HasVersion(DataRowVersion.Proposed) Then
If dataRow(0, DataRowVersion.Current) Is dataRow(0, DataRowVersion.Proposed) Then
Console.WriteLine("The original and the proposed are the same.")
dataRow.CancelEdit()
Else
dataRow.AcceptChanges()
Console.WriteLine("The original and the proposed are different.")
End If
End If
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
注解
DataRowVersion当使用对象的或的检索中找到的值时,将使用这些值 DataRow Item[] GetChildRows DataRow 。The DataRowVersion values are used when retrieving the value found in a DataRow using Item[] or the GetChildRows of the DataRow object.
将 DataRowVersion 通知您存在哪个版本的 DataRow 。The DataRowVersion informs you what version of a DataRow exists. 版本在下列情况下发生更改:Versions change under the following circumstances:
在调用 DataRow 对象的 BeginEdit 方法之后,如果更改该值,则
Current
和值将Proposed
变为可用。After calling the DataRow object's BeginEdit method, if you change the value, theCurrent
andProposed
values become available.在调用 DataRow 对象的 CancelEdit 方法后,将
Proposed
删除该值。After calling the DataRow object's CancelEdit method, theProposed
value is deleted.在调用 DataRow 对象的 EndEdit 方法后,建议的值将变为
Current
值。After calling the DataRow object's EndEdit method, the Proposed value becomes theCurrent
value.调用 DataRow 对象的方法后 AcceptChanges ,
Original
该值将与Current
值相同。After calling the DataRow object's AcceptChanges method, theOriginal
value becomes identical to theCurrent
value.调用 DataTable 对象的方法后 AcceptChanges ,
Original
该值将与Current
值相同。After calling the DataTable object's AcceptChanges method, theOriginal
value becomes identical to theCurrent
value.在调用 DataRow 对象的 RejectChanges 方法之后,
Proposed
会丢弃该值,版本将变为Current
。After calling the DataRow object's RejectChanges method, theProposed
value is discarded, and the version becomesCurrent
.