DataRowVersion 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
說明 DataRow 的版本。
public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion =
Public Enum DataRowVersion
- 繼承
欄位
Current | 512 | 資料列包含目前的值。 |
Default | 1536 | DataRowState 的預設版本。 針對 |
Original | 256 | 資料列包含其原始值。 |
Proposed | 1024 | 資料列包含建議值。 |
範例
下列範例會在叫用 方法之前檢查 DataRowVersion 的 DataRowAcceptChanges 。
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擷取 在 DataRow 中找到的值時Item[],會使用 或 GetChildRowsDataRow 物件的 。
會 DataRowVersion 通知您存在哪個版本的 DataRow 。 在下列情況下,版本會變更:
呼叫 DataRow 物件的 BeginEdit 方法之後,如果您變更值,
Current
和Proposed
值就會變成可用。呼叫 DataRow 物件的 CancelEdit 方法之後,會
Proposed
刪除值。呼叫 DataRow 物件的 AcceptChanges 方法之後,值
Original
會變成與Current
值相同的值。呼叫 DataTable 物件的 AcceptChanges 方法之後,值
Original
會變成與Current
值相同的值。呼叫 DataRow 物件的 RejectChanges 方法之後,會
Proposed
捨棄值,而版本會Current
變成 。