This documentation is archived and is not being maintained.

DataRow.Item Property (Int32, DataRowVersion)

Gets the data stored in the column, specified by index and version of the data to retrieve.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

public Object this[
	int columnIndex,
	DataRowVersion version
] { get; }


Type: System.Int32

The zero-based index of the column.

Type: System.Data.DataRowVersion

One of the DataRowVersion values that specifies the row version that you want. Possible values are Default, Original, Current, and Proposed.

Property Value

Type: System.Object
An Object that contains the data.


The columnIndex argument is out of range.


The data types of the value and the column do not match.


The row does not have this version of data.


An attempt was made to set a value on a deleted row.

You can only create or update a row after you call the BeginEdit method; similarly, the EndEdit method must be called to commit the edit. After you call the EndEdit method, and before you call the AcceptChanges method, internal representations of the original and new proposed values are stored. Therefore, until you call the AcceptChanges, you can use the version argument to specify which version of a column's value you need, either the DataRowVersion.Original or DataRowVersion.Proposed. However, as soon as you call the AcceptChanges method, the version of the column reverts to DataRowVersion.Original. If the row is new, you can also pass DataRowVersion.Default for the parameter to retrieve the column's default value. When passing DataRowVersion.Current, the property returns the current value, whatever its version may be.


The BeginEdit method is called implicitly when you change the value of a data-bound control or when a DataRow object is added to the DataRowCollection; the EndEdit method is called implicitly when you call the following methods: the AcceptChanges method of the DataRow object, the AcceptChanges method of the DataTable object, or the CancelEdit method.

By contrast, the DataRowVersion enumeration Current returns the version of the data after the EndEdit method has been called.

The version argument should not be confused with the RowState property. The version argument describes the state of the data that is contained by the column relative to the column's original value. The RowState property describes the state of the whole row relative to its parent DataTable.

When you set the property, an exception is generated if an exception occurs in the ColumnChanging event.

If this is an immediate edit, see EndEdit for the exceptions that can be generated.

The following example gets the current value of a column through the Item property of the DataRow object.

Private Sub DataGrid1_Click _
    (ByVal sender As System.Object, ByVal e As System.EventArgs)

    ' Set the current row using the RowNumber property of the CurrentCell. 
    Dim currentRow As DataRow = CType(DataGrid1.DataSource, DataTable). _

    ' Get the value of the column 1 in the DataTable.
    label1.Text = currentRow(1, DataRowVersion.Current).ToString()
End Sub

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0