Field(T) Method (DataRow, Int32, DataRowVersion)

DataRowExtensions.Field(Of T) Method (DataRow, Int32, DataRowVersion)

 

Provides strongly-typed access to each of the column values in the specified row. The Field(Of T) method also supports nullable types.

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

<ExtensionAttribute>
Public Shared Function Field(Of T) (
	row As DataRow,
	columnIndex As Integer,
	version As DataRowVersion
) As T

Parameters

row
Type: System.Data.DataRow

The input DataRow, which acts as the this instance for the extension method.

columnIndex
Type: System.Int32

The zero-based ordinal of the column to return the value of.

version
Type: System.Data.DataRowVersion

A DataRowVersion enumeration that specifies the version of the column value to return, such as Current or Original version.

Return Value

Type: T

The value, of type T, of the DataColumn specified by ordinal and version.

Type Parameters

T

A generic parameter that specifies the return type of the column.

Exception Condition
InvalidCastException

The value type of the underlying column could not be cast to the type specified by the generic parameter, T.

IndexOutOfRangeException

The column specified by ordinal does not exist in the DataTable that the DataRow is a part of.

NullReferenceException

A null value was assigned to a non-nullable type.

The DataSet class represents null values with the Value instance of the DBNull class. A Language-Integrated Query (LINQ) expression that accessed a column with a null value would generate a InvalidCastException at run time. Additionally, DataSet doesn’t support nullable types. The Field(Of T) method provides support for accessing columns as nullable types. If the underlying value in the DataSet is Value, the returned nullable type will have a value of null.

If the value of the specified DataColumn is null and T is a reference type or nullable type, then the return type will be null. The Field(Of T) method will not return Value.

The Field(Of T) method does not perform type conversions. If type conversion is required, you should first obtain the column value by using the Field(Of T) method. The column value should then be converted to another type.

.NET Framework
Available since 3.5
Return to top
Show:
© 2016 Microsoft