DataRowVersion Wyliczenie

Definicja

Opisuje wersję DataRow.

public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion = 
Public Enum DataRowVersion
Dziedziczenie
DataRowVersion

Pola

Nazwa Wartość Opis
Original 256

Wiersz zawiera jego oryginalne wartości.

Current 512

Wiersz zawiera bieżące wartości.

Proposed 1024

Wiersz zawiera proponowaną wartość.

Default 1536

Domyślna wersja programu DataRowState. W przypadku wartości , lub domyślną wersją DataRowState jest Current.DeletedModifiedAdded W przypadku DataRowState wartości parametru Detachedwersja to Proposed.

Przykłady

Poniższy przykład sprawdza element DataRowVersionDataRow przed wywołaniem AcceptChanges metody .

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

Uwagi

Wartości DataRowVersion są używane podczas pobierania wartości znalezionej w metodzie DataRow lub Item[]GetChildRowsDataRow obiekcie .

Element DataRowVersion informuje o tym, jaka wersja istnieje DataRow . Wersje zmieniają się w następujących okolicznościach:

  • Po wywołaniu DataRow metody obiektu BeginEdit , jeśli zmienisz wartość, Current wartości i Proposed staną się dostępne.

  • Po wywołaniu DataRow metody Proposed obiektu CancelEdit wartość zostanie usunięta.

  • Po wywołaniu DataRow metody obiektu EndEdit wartość Proponowane staje się wartością Current .

  • Po wywołaniu DataRow metody Original obiektu AcceptChanges wartość staje się identyczna z wartościąCurrent.

  • Po wywołaniu DataTable metody Original obiektu AcceptChanges wartość staje się identyczna z wartościąCurrent.

  • Po wywołaniu DataRow metody Proposed obiektu RejectChanges wartość zostanie odrzucona, a wersja stanie się .Current

Dotyczy

Zobacz też