DataRowVersion DataRowVersion DataRowVersion DataRowVersion Enum

定义

介绍 DataRow 的版本。Describes the version of a DataRow.

public enum class DataRowVersion
public enum DataRowVersion
type DataRowVersion = 
Public Enum DataRowVersion
继承
DataRowVersionDataRowVersionDataRowVersionDataRowVersion

字段

Current Current Current Current 512

包含其当前值的行。The row contains current values.

Default Default Default Default 1536

DataRowState 的默认版本。The default version of DataRowState. 对于 AddedModifiedDeletedDataRowState 值,默认的版本是 CurrentFor a DataRowState value of Added, Modified or Deleted, the default version is Current. 对于 DetachedDataRowState 值,版本是 ProposedFor a DataRowState value of Detached, the version is Proposed.

Original Original Original Original 256

包含其原始值的行。The row contains its original values.

Proposed Proposed Proposed Proposed 1024

包含建议值的行。The row contains a proposed value.

示例

以下示例检查DataRowVersionDataRow然后再调用AcceptChanges方法。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

注解

DataRowVersion检索的值中找到时将使用值DataRow使用Item[String, DataRowVersion]GetChildRowsDataRow对象。The DataRowVersion values are used when retrieving the value found in a DataRow using Item[String, DataRowVersion] or the GetChildRows of the DataRow object.

DataRowVersion会通知你哪些版本的DataRow存在。The DataRowVersion informs you what version of a DataRow exists. 在以下情况下更改版本:Versions change under the following circumstances:

  • 在调用DataRow对象的BeginEdit方法时,如果更改此值,CurrentProposed值变得可用。After calling the DataRow object's BeginEdit method, if you change the value, the Current and Proposed values become available.

  • 在调用DataRow对象的CancelEdit方法,Proposed删除值。After calling the DataRow object's CancelEdit method, the Proposed value is deleted.

  • 在调用DataRow对象的EndEdit方法,建议值将成为Current值。After calling the DataRow object's EndEdit method, the Proposed value becomes the Current value.

  • 在调用DataRow对象的AcceptChanges方法,Original值将成为相同Current值。After calling the DataRow object's AcceptChanges method, the Original value becomes identical to the Current value.

  • 在调用DataTable对象的AcceptChanges方法,Original值将成为相同Current值。After calling the DataTable object's AcceptChanges method, the Original value becomes identical to the Current value.

  • 在调用DataRow对象的RejectChanges方法,Proposed值将被丢弃,并成为版本CurrentAfter calling the DataRow object's RejectChanges method, the Proposed value is discarded, and the version becomes Current.

适用于

另请参阅