DataRowVersion Énumération
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Décrit la version d’une DataRow.
public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion =
Public Enum DataRowVersion
- Héritage
Champs
Current | 512 | La ligne contient les valeurs actuelles. |
Default | 1536 | La version par défaut de DataRowState. Pour une valeur |
Original | 256 | La ligne contient ses valeurs d’origine. |
Proposed | 1024 | La ligne contient une valeur proposée. |
Exemples
L’exemple suivant vérifie l’appel DataRowVersion d’une DataRow méthode avant d’appeler la AcceptChanges méthode.
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
Remarques
Les DataRowVersion valeurs sont utilisées lors de la récupération de la valeur trouvée dans une DataRow utilisation Item[] ou GetChildRows de l’objet DataRow .
Il DataRowVersion vous informe de la version d’un DataRow existe. Les versions changent dans les circonstances suivantes :
Après avoir appelé la méthode de BeginEdit l’objetDataRow, si vous modifiez la valeur, les
Current
valeurs etProposed
deviennent disponibles.Après avoir appelé la méthode de CancelEdit l’objetDataRow, la
Proposed
valeur est supprimée.Après avoir appelé la méthode de EndEdit l’objetDataRow, la valeur proposée devient la
Current
valeur.Après avoir appelé la méthode de AcceptChanges l’objetDataRow, la
Original
valeur devient identique à laCurrent
valeur.Après avoir appelé la méthode de AcceptChanges l’objetDataTable, la
Original
valeur devient identique à laCurrent
valeur.Après avoir appelé la méthode de RejectChanges l’objetDataRow, la
Proposed
valeur est ignorée et la version devientCurrent
.