DataRowVersion DataRowVersion DataRowVersion DataRowVersion Enum

Definizione

Descrive la versione di un oggetto DataRow.Describes the version of a DataRow.

public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion = 
Public Enum DataRowVersion
Ereditarietà
DataRowVersionDataRowVersionDataRowVersionDataRowVersion

Campi

Current Current Current Current 512

Riga contenente i valori correnti.The row contains current values.

Default Default Default Default 1536

Versione predefinita di DataRowState.The default version of DataRowState. Per un valore DataRowState di Added, Modified o Deleted, la versione predefinita è Current.For a DataRowState value of Added, Modified or Deleted, the default version is Current. Per un valore DataRowState di Detached, la versione predefinita è Proposed.For a DataRowState value of Detached, the version is Proposed.

Original Original Original Original 256

Riga contenente i valori originali.The row contains its original values.

Proposed Proposed Proposed Proposed 1024

Riga contenente un valore proposto.The row contains a proposed value.

Esempi

Nell'esempio seguente viene controllato DataRowVersion il valore DataRow di un oggetto prima AcceptChanges di richiamare il metodo.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

Commenti

I DataRowVersion valori vengono usati durante il recupero del valore trovato in un DataRow DataRow oggetto Item[String, DataRowVersion] usando o GetChildRows dell'oggetto.The DataRowVersion values are used when retrieving the value found in a DataRow using Item[String, DataRowVersion] or the GetChildRows of the DataRow object.

Informa DataRowVersion la versione di a DataRow esistente.The DataRowVersion informs you what version of a DataRow exists. Le versioni cambiano nelle circostanze seguenti:Versions change under the following circumstances:

  • Dopo la chiamata DataRow al BeginEdit metodo dell'oggetto, se si modifica il valore, Current i Proposed valori e diventano disponibili.After calling the DataRow object's BeginEdit method, if you change the value, the Current and Proposed values become available.

  • Dopo la chiamata DataRow al CancelEdit metodo dell'oggetto, Proposed il valore viene eliminato.After calling the DataRow object's CancelEdit method, the Proposed value is deleted.

  • Dopo la chiamata DataRow al EndEdit metodo dell'oggetto, il valore proposto diventa Current il valore.After calling the DataRow object's EndEdit method, the Proposed value becomes the Current value.

  • Dopo la chiamata DataRow al AcceptChanges metodo dell'oggetto, Original il valore diventa identico Current al valore.After calling the DataRow object's AcceptChanges method, the Original value becomes identical to the Current value.

  • Dopo la chiamata DataTable al AcceptChanges metodo dell'oggetto, Original il valore diventa identico Current al valore.After calling the DataTable object's AcceptChanges method, the Original value becomes identical to the Current value.

  • Dopo la chiamata DataRow al RejectChanges metodo dell'oggetto, Proposed il valore viene ignorato e la versione diventa Current.After calling the DataRow object's RejectChanges method, the Proposed value is discarded, and the version becomes Current.

Si applica a

Vedi anche