DataRowExtensions.Field<T> Method (DataRow, String, DataRowVersion)
Provides strongly-typed access to each of the column values in the specified row. The Field method also supports nullable types.
Assembly: System.Data.DataSetExtensions (in System.Data.DataSetExtensions.dll)
public static T Field<T>( this DataRow row, string columnName, DataRowVersion version )
A generic parameter that specifies the return type of the column.
- Type: System.Data.DataRow
The input DataRow, which acts as the this instance for the extension method.
- Type: System.String
The name of the column to return the value of.
The value, of type T, of the DataColumn specified by columnName and version.
Usage NoteIn Visual Basic and C#, you can call this method as an instance method on any object of type DataRow. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
The value type of the underlying column could not be cast to the type specified by the generic parameter, T.
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 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.
The Field method does not perform type conversions. If type conversion is required, you should first obtain the column value by using the Field method. The column value should then be converted to another type.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC
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.