Edit

Share via


DataRowVersion Enum

Definition

Describes the version of a DataRow.

C#
public enum DataRowVersion
Inheritance
DataRowVersion

Fields

Name Value Description
Original 256

The row contains its original values.

Current 512

The row contains current values.

Proposed 1024

The row contains a proposed value.

Default 1536

The default version of DataRowState. For a DataRowState value of Added, Modified or Deleted, the default version is Current. For a DataRowState value of Detached, the version is Proposed.

Examples

The following example checks the DataRowVersion of a DataRow before invoking the AcceptChanges method.

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

Remarks

The DataRowVersion values are used when retrieving the value found in a DataRow using Item[] or the GetChildRows of the DataRow object.

The DataRowVersion informs you what version of a DataRow exists. Versions change under the following circumstances:

  • After calling the DataRow object's BeginEdit method, if you change the value, the Current and Proposed values become available.

  • After calling the DataRow object's CancelEdit method, the Proposed value is deleted.

  • After calling the DataRow object's EndEdit method, the Proposed value becomes the Current value.

  • After calling the DataRow object's AcceptChanges method, the Original value becomes identical to the Current value.

  • After calling the DataTable object's AcceptChanges method, the Original value becomes identical to the Current value.

  • After calling the DataRow object's RejectChanges method, the Proposed value is discarded, and the version becomes Current.

Applies to

Product Versions
.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

See also