DataRowVersion 列舉

定義

說明 DataRow 的版本。Describes the version of a DataRow.

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

欄位

Current 512

資料列包含目前的值。The row contains current values.

Default 1536

DataRowState 的預設版本。The default version of DataRowState. 針對 DataRowStateAddedModifiedDeleted 值,預設版本是 CurrentFor a DataRowState value of Added, Modified or Deleted, the default version is Current. 針對 DataRowStateDetached 值,版本是 ProposedFor a DataRowState value of Detached, the version is Proposed.

Original 256

資料列包含其原始值。The row contains its original values.

Proposed 1024

資料列包含建議值。The row contains a proposed value.

範例

下列範例會先檢查 DataRowDataRowVersion,再叫用 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

備註

使用 Item[String, DataRowVersion]DataRow 物件的 GetChildRows 來抓取 DataRow 中找到的值時,會使用 DataRowVersion 值。The DataRowVersion values are used when retrieving the value found in a DataRow using Item[String, DataRowVersion] 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 方法之後,如果您變更此值,CurrentProposed 值就會變成可用。After calling the DataRow object's BeginEdit method, if you change the value, the Current and Proposed values become available.

  • 呼叫 DataRow 物件的 CancelEdit 方法之後,會刪除 Proposed 值。After calling the DataRow object's CancelEdit method, the Proposed value is deleted.

  • 呼叫 DataRow 物件的 EndEdit 方法之後,建議的值會變成 Current 值。After calling the DataRow object's EndEdit method, the Proposed value becomes the Current value.

  • 呼叫 DataRow 物件的 AcceptChanges 方法之後,Original 值會與 Current 值相同。After calling the DataRow object's AcceptChanges method, the Original value becomes identical to the Current value.

  • 呼叫 DataTable 物件的 AcceptChanges 方法之後,Original 值會與 Current 值相同。After calling the DataTable object's AcceptChanges method, the Original value becomes identical to the Current value.

  • 呼叫 DataRow 物件的 RejectChanges 方法之後,會捨棄 Proposed 值,而版本會變成 CurrentAfter calling the DataRow object's RejectChanges method, the Proposed value is discarded, and the version becomes Current.

適用於

另請參閱