DataRowVersion 列挙型
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
DataRowのバージョンについて説明します。
public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion =
Public Enum DataRowVersion
- 継承
フィールド
| 名前 | 値 | 説明 |
|---|---|---|
| Original | 256 | 行には元の値が含まれています。 |
| Current | 512 | 行には現在の値が含まれています。 |
| Proposed | 1024 | この行には、提案された値が含まれています。 |
| Default | 1536 |
DataRowStateの既定のバージョン。
|
例
次の例では、AcceptChanges メソッドを呼び出す前に、DataRowのDataRowVersionを確認します。
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値は、Item[]またはDataRow オブジェクトのGetChildRowsを使用してDataRowで見つかった値を取得するときに使用されます。
DataRowVersionは、存在するDataRowのバージョンを通知します。 バージョンは、次の状況で変更されます。
DataRow オブジェクトの BeginEdit メソッドを呼び出した後、値を変更すると、
CurrentとProposedの値が使用可能になります。DataRow オブジェクトの CancelEdit メソッドを呼び出すと、
Proposed値が削除されます。DataRow オブジェクトのAcceptChanges メソッドを呼び出すと、
Original値はCurrent値と同じになります。DataTable オブジェクトのAcceptChanges メソッドを呼び出すと、
Original値はCurrent値と同じになります。DataRow オブジェクトのRejectChanges メソッドを呼び出すと、
Proposed値が破棄され、バージョンがCurrentになります。