DataRowVersion 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
描述 DataRow的版本。
public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion =
Public Enum DataRowVersion
- 繼承
欄位
| 名稱 | 值 | Description |
|---|---|---|
| Original | 256 | 該列包含其原始值。 |
| Current | 512 | 該列包含目前的數值。 |
| Proposed | 1024 | 該列包含一個建議值。 |
| Default | 1536 | 預設版本。DataRowState 對於 |
範例
以下範例在呼叫該DataRowVersion方法前檢查 a DataRow 的 。AcceptChanges
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這些值用於取回物件使用DataRowItem[]GetChildRows中DataRow發現的值。
它 DataRowVersion 告訴你存在哪個版本的 a DataRow 。 版本在以下情況下會變動:
呼叫 DataRow 物件 CancelEdit 的方法後,該
Proposed值會被刪除。呼叫DataRowAcceptChanges物件的方法後,值
Original會與值Current完全相同。呼叫DataTableAcceptChanges物件的方法後,值
Original會與值Current完全相同。呼叫DataRowRejectChanges物件方法後,
Proposed該值會被捨棄,版本變為Current。