DataRowVersion 枚举

定义

介绍 DataRow 的版本。

C#
public enum DataRowVersion
继承
DataRowVersion

字段

名称 说明
Current 512

包含其当前值的行。

Default 1536

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

Original 256

包含其原始值的行。

Proposed 1024

包含建议值的行。

示例

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

C#
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;
}

注解

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

适用于

产品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

另请参阅