DataRowVersion 枚举

定义

介绍 DataRow 的版本。

public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion = 
Public Enum DataRowVersion
继承
DataRowVersion

字段

Current 512

包含其当前值的行。

Default 1536

DataRowState 的默认版本。 对于 AddedModifiedDeletedDataRowState 值,默认的版本是 Current。 对于 DetachedDataRowState 值,版本是 Proposed

Original 256

包含其原始值的行。

Proposed 1024

包含建议值的行。

示例

以下示例在调用 AcceptChanges 方法之前检查 DataRowVersionDataRow

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在 using 或 GetChildRows 对象的 中找到DataRowItem[]的值时,DataRow将使用这些值。

告知 DataRowVersion 你存在的 版本 DataRow 。 版本在以下情况下会更改:

  • 调用 DataRow 对象的 BeginEdit 方法后,如果更改值,则 CurrentProposed 值将变为可用。

  • 调用 DataRow 对象的 CancelEdit 方法后,将 Proposed 删除该值。

  • 调用 DataRow 对象的 EndEdit 方法后,建议的值将成为 Current 值。

  • 调用 DataRow 对象的 AcceptChanges 方法后, Original 该值将变为与 值相同的 Current

  • 调用 DataTable 对象的 AcceptChanges 方法后, Original 该值将变为与 值相同的 Current

  • 调用 DataRow 对象的 RejectChanges 方法后,值 Proposed 将被丢弃,版本变为 Current

适用于

另请参阅