DataRowVersion Enumeração

Definição

Descreve a versão de um DataRow.Describes the version of a DataRow.

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

Campos

Current 512

A linha contém os valores atuais.The row contains current values.

Default 1536

A versão padrão do DataRowState.The default version of DataRowState. Para um valor DataRowState igual a Added, Modified ou Deleted, a versão padrão é Current.For a DataRowState value of Added, Modified or Deleted, the default version is Current. Para um valor DataRowState igual a Detached, a versão é Proposed.For a DataRowState value of Detached, the version is Proposed.

Original 256

A linha contém os valores originais.The row contains its original values.

Proposed 1024

A linha contém um valor proposto.The row contains a proposed value.

Exemplos

O exemplo a seguir verifica DataRowVersion o de DataRow um antes de invocar o AcceptChanges método.The following example checks the DataRowVersion of a DataRow before invoking the AcceptChanges method.

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

Comentários

Os DataRowVersion valores são usados ao recuperar o valor encontrado em um DataRow DataRow usando Item[String, DataRowVersion] o ou o GetChildRows do objeto.The DataRowVersion values are used when retrieving the value found in a DataRow using Item[String, DataRowVersion] or the GetChildRows of the DataRow object.

O DataRowVersion informa qual versão DataRow do existe.The DataRowVersion informs you what version of a DataRow exists. As versões são alteradas nas seguintes circunstâncias:Versions change under the following circumstances:

  • Depois de chamar DataRow o método BeginEdit do objeto, se você alterar o valor, Current os Proposed valores e serão disponibilizados.After calling the DataRow object's BeginEdit method, if you change the value, the Current and Proposed values become available.

  • Depois de chamar DataRow o método CancelEdit do objeto, Proposed o valor é excluído.After calling the DataRow object's CancelEdit method, the Proposed value is deleted.

  • Depois de chamar DataRow o método EndEdit do objeto, o valor proposto torna Current -se o valor.After calling the DataRow object's EndEdit method, the Proposed value becomes the Current value.

  • Depois de chamar DataRow o método AcceptChanges do objeto, Original o valor se torna idêntico Current ao valor.After calling the DataRow object's AcceptChanges method, the Original value becomes identical to the Current value.

  • Depois de chamar DataTable o método AcceptChanges do objeto, Original o valor se torna idêntico Current ao valor.After calling the DataTable object's AcceptChanges method, the Original value becomes identical to the Current value.

  • Depois de chamar DataRow o método RejectChanges do objeto, Proposed o valor é Descartado e a versão se torna Current.After calling the DataRow object's RejectChanges method, the Proposed value is discarded, and the version becomes Current.

Aplica-se a

Veja também