DataRowVersion Enumeração

Definição

Descreve a versão de um DataRow.

public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion = 
Public Enum DataRowVersion
Herança
DataRowVersion

Campos

Name Valor Description
Original 256

A linha contém os seus valores originais.

Current 512

A linha contém valores atuais.

Proposed 1024

A linha contém um valor proposto.

Default 1536

A versão padrão de DataRowState. Para um DataRowState valor de Added, Modified ou Deleted, a versão padrão é Current. Para um DataRowState valor de Detached, a versão é Proposed.

Exemplos

O exemplo seguinte verifica o DataRowVersion de a DataRow antes de invocar o AcceptChanges método.

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

Observações

Os DataRowVersion valores são usados ao recuperar o valor encontrado num DataRow uso Item[] ou no GetChildRows do DataRow objeto.

Informa DataRowVersion que versão de um DataRow existe. As versões mudam nas seguintes circunstâncias:

  • Depois de chamar o DataRow método do BeginEdit objeto, se alterar o valor, os Current valores e Proposed ficam disponíveis.

  • Após chamar o DataRow método do CancelEdit objeto, o Proposed valor é eliminado.

  • Após chamar o DataRow método do EndEdit objeto, o valor Proposto torna-se o Current valor.

  • Depois de chamar o DataRow método do AcceptChanges objeto, o Original valor torna-se idêntico ao Current valor.

  • Depois de chamar o DataTable método do AcceptChanges objeto, o Original valor torna-se idêntico ao Current valor.

  • Depois de chamar o DataRow método do RejectChanges objeto, o Proposed valor é descartado, e a versão torna-se Current.

Aplica-se a

Ver também