DataRowExtensions.Field 方法

定义

提供对 DataRow 中的每个列值的强类型访问。Provides strongly-typed access to each of the column values in the DataRow.

重载

Field<T>(DataRow, DataColumn)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, DataColumn) 方法还支持可以为 null 的类型。The Field<T>(DataRow, DataColumn) method also supports nullable types.

Field<T>(DataRow, Int32)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, Int32) 方法还支持可以为 null 的类型。The Field<T>(DataRow, Int32) method also supports nullable types.

Field<T>(DataRow, String)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, String) 方法还支持可以为 null 的类型。The Field<T>(DataRow, String) method also supports nullable types.

Field<T>(DataRow, DataColumn, DataRowVersion)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, DataColumn, DataRowVersion) 方法还支持可以为 null 的类型。The Field<T>(DataRow, DataColumn, DataRowVersion) method also supports nullable types.

Field<T>(DataRow, Int32, DataRowVersion)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, Int32, DataRowVersion) 方法还支持可以为 null 的类型。The Field<T>(DataRow, Int32, DataRowVersion) method also supports nullable types.

Field<T>(DataRow, String, DataRowVersion)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, String, DataRowVersion) 方法还支持可以为 null 的类型。The Field<T>(DataRow, String, DataRowVersion) method also supports nullable types.

Field<T>(DataRow, DataColumn)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, DataColumn) 方法还支持可以为 null 的类型。The Field<T>(DataRow, DataColumn) method also supports nullable types.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T Field(System::Data::DataRow ^ row, System::Data::DataColumn ^ column);
public static T Field<T> (this System.Data.DataRow row, System.Data.DataColumn column);
public static T? Field<T> (this System.Data.DataRow row, System.Data.DataColumn column);
static member Field : System.Data.DataRow * System.Data.DataColumn -> 'T
<Extension()>
Public Function Field(Of T) (row As DataRow, column As DataColumn) As T

类型参数

T

指定列的返回类型的泛型形参。A generic parameter that specifies the return type of the column.

参数

row
DataRow

输入 DataRow,作为扩展方法的 this 实例。The input DataRow, which acts as the this instance for the extension method.

column
DataColumn

输入 DataColumn 对象,该对象指定要返回其值的列。The input DataColumn object that specifies the column to return the value of.

返回

T

column 指定的 T 类型的 DataColumn 值。The value, of type T, of the DataColumn specified by column.

例外

基础列的值类型无法转换为泛型参数 T 指定的类型。The value type of the underlying column could not be cast to the type specified by the generic parameter, T.

column 指定的列不会出现在包含 DataRowDataTable 中。The column specified by column does not occur in the DataTable that the DataRow is a part of.

将“null”值赋给了不可为 null 的类型。A null value was assigned to a non-nullable type.

注解

DataSet类用类的实例表示 nullValue DBNullThe DataSet class represents null values with the Value instance of the DBNull class. Language-Integrated 查询 (LINQ) 表达式,该表达式访问包含 null 值的列时,将 InvalidCastException 在运行时生成。A Language-Integrated Query (LINQ) expression that accessed a column with a null value would generate a InvalidCastException at run time. 此外,不 DataSet 支持可以为 null 的类型。Additionally, DataSet does not support nullable types. Field方法为将列访问为可以为 null 的类型提供支持。The Field method provides support for accessing columns as nullable types. 如果中的基础值 DataSetValue ,则返回的可以为 null 的类型的值为 nullIf the underlying value in the DataSet is Value, the returned nullable type will have a value of null.

如果指定的值 DataColumnValue ,并且 T 是引用类型或可以为 null 的类型,则返回类型将为 nullIf the value of the specified DataColumn is Value and T is a reference type or nullable type, the return type will be null. Field方法不会返回 ValueThe Field method will not return Value.

Field方法不执行类型转换。The Field method does not perform type conversions. 如果需要类型转换,则应首先使用方法获取列值 FieldIf 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.

适用于

Field<T>(DataRow, Int32)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, Int32) 方法还支持可以为 null 的类型。The Field<T>(DataRow, Int32) method also supports nullable types.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T Field(System::Data::DataRow ^ row, int columnIndex);
public static T Field<T> (this System.Data.DataRow row, int columnIndex);
public static T? Field<T> (this System.Data.DataRow row, int columnIndex);
static member Field : System.Data.DataRow * int -> 'T
<Extension()>
Public Function Field(Of T) (row As DataRow, columnIndex As Integer) As T

类型参数

T

指定列的返回类型的泛型形参。A generic parameter that specifies the return type of the column.

参数

row
DataRow

输入 DataRow,作为扩展方法的 this 实例。The input DataRow, which acts as the this instance for the extension method.

columnIndex
Int32

列索引。The column index.

返回

T

columnIndex 指定的 T 类型的 DataColumn 值。The value, of type T, of the DataColumn specified by columnIndex.

例外

基础列的值类型无法转换为泛型参数 T 指定的类型。The value type of the underlying column could not be cast to the type specified by the generic parameter, T.

ordinal 指定的列不存在于包含 DataRowDataTable 中。The column specified by ordinal does not exist in the DataTable that the DataRow is a part of.

将“null”值赋给了不可为 null 的类型。A null value was assigned to a non-nullable type.

注解

DataSet类用类的实例表示 nullValue DBNullThe DataSet class represents null values with the Value instance of the DBNull class. Language-Integrated 查询 (LINQ) 表达式,该表达式访问包含 null 值的列时,将 InvalidCastException 在运行时生成。A Language-Integrated Query (LINQ) expression that accessed a column with a null value would generate a InvalidCastException at run time. 此外, DataSet 不支持可以为 null 的类型。Additionally, DataSet doesn't support nullable types. Field方法为将列访问为可以为 null 的类型提供支持。The Field method provides support for accessing columns as nullable types. 如果中的基础值 DataSetValue ,则返回的可以为 null 的类型的值为 nullIf the underlying value in the DataSet is Value, the returned nullable type will have a value of null.

如果指定的值 DataColumnnull 并且 T 是引用类型或可以为 null 的类型,则返回类型将为 nullIf the value of the specified DataColumn is null and T is a reference type or nullable type, then the return type will be null. Field方法不会返回 ValueThe Field method will not return Value.

Field方法不执行类型转换。The Field method does not perform type conversions. 如果需要类型转换,则应首先使用方法获取列值 FieldIf 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.

适用于

Field<T>(DataRow, String)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, String) 方法还支持可以为 null 的类型。The Field<T>(DataRow, String) method also supports nullable types.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T Field(System::Data::DataRow ^ row, System::String ^ columnName);
public static T Field<T> (this System.Data.DataRow row, string columnName);
public static T? Field<T> (this System.Data.DataRow row, string columnName);
static member Field : System.Data.DataRow * string -> 'T
<Extension()>
Public Function Field(Of T) (row As DataRow, columnName As String) As T

类型参数

T

指定列的返回类型的泛型形参。A generic parameter that specifies the return type of the column.

参数

row
DataRow

输入 DataRow,作为扩展方法的 this 实例。The input DataRow, which acts as the this instance for the extension method.

columnName
String

要返回其值的列名称。The name of the column to return the value of.

返回

T

columnName 指定的 T 类型的 DataColumn 值。The value, of type T, of the DataColumn specified by columnName.

例外

基础列的值类型无法转换为泛型参数 T 指定的类型。The value type of the underlying column could not be cast to the type specified by the generic parameter, T.

columnName 指定的列不会出现在包含 DataRowDataTable 中。The column specified by columnName does not occur in the DataTable that the DataRow is a part of.

null 值分配给不可为 null 的类型。A null value was assigned to a non-nullable type.

注解

DataSet类用类的实例表示 nullValue DBNullThe DataSet class represents null values with the Value instance of the DBNull class. Language-Integrated 查询 (LINQ) 表达式,该表达式访问包含 null 值的列时,将 InvalidCastException 在运行时生成。A Language-Integrated Query (LINQ) expression that accessed a column with a null value would generate a InvalidCastException at run time. 此外,不 DataSet 支持可以为 null 的类型。Additionally, DataSet does not support nullable types. Field方法为将列访问为可以为 null 的类型提供支持。The Field method provides support for accessing columns as nullable types. 如果中的基础值 DataSetValue ,则返回的可以为 null 的类型的值为 nullIf the underlying value in the DataSet is Value, the returned nullable type will have a value of null.

如果指定的值 DataColumnnull 并且 T 是引用类型或可以为 null 的类型,则返回类型将为 nullIf the value of the specified DataColumn is null and T is a reference type or nullable type, the return type will be null. Field方法不会返回 ValueThe Field method will not return Value.

Field方法不执行类型转换。The Field method does not perform type conversions. 如果需要类型转换,则应首先使用方法获取列值 FieldIf 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.

适用于

Field<T>(DataRow, DataColumn, DataRowVersion)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, DataColumn, DataRowVersion) 方法还支持可以为 null 的类型。The Field<T>(DataRow, DataColumn, DataRowVersion) method also supports nullable types.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T Field(System::Data::DataRow ^ row, System::Data::DataColumn ^ column, System::Data::DataRowVersion version);
public static T Field<T> (this System.Data.DataRow row, System.Data.DataColumn column, System.Data.DataRowVersion version);
public static T? Field<T> (this System.Data.DataRow row, System.Data.DataColumn column, System.Data.DataRowVersion version);
static member Field : System.Data.DataRow * System.Data.DataColumn * System.Data.DataRowVersion -> 'T
<Extension()>
Public Function Field(Of T) (row As DataRow, column As DataColumn, version As DataRowVersion) As T

类型参数

T

指定列的返回类型的泛型形参。A generic parameter that specifies the return type of the column.

参数

row
DataRow

输入 DataRow,作为扩展方法的 this 实例。The input DataRow, which acts as the this instance for the extension method.

column
DataColumn

输入 DataColumn 对象,该对象指定要返回其值的列。The input DataColumn object that specifies the column to return the value of.

version
DataRowVersion

DataRowVersion 枚举,指定要返回的列值版本,如 CurrentOriginal 版本。A DataRowVersion enumeration that specifies the version of the column value to return, such as Current or Original version.

返回

T

columnversion 指定的 T 类型的 DataColumn 值。The value, of type T, of the DataColumn specified by column and version.

例外

基础列的值类型无法转换为泛型参数 T 指定的类型。The value type of the underlying column could not be cast to the type specified by the generic parameter, T.

column 指定的列不存在于包含 DataRowDataTable 中。The column specified by column does not exist in the DataTable that the DataRow is a part of.

将“null”值赋给了不可为 null 的类型。A null value was assigned to a non-nullable type.

注解

DataSet类用类的实例表示 nullValue DBNullThe DataSet class represents null values with the Value instance of the DBNull class. Language-Integrated 查询 (LINQ) 表达式,该表达式访问包含 null 值的列时,将 InvalidCastException 在运行时生成。A Language-Integrated Query (LINQ) expression that accessed a column with a null value would generate a InvalidCastException at run time. 此外, DataSet 不支持可以为 null 的类型。Additionally, DataSet doesn't support nullable types. Field方法为将列访问为可以为 null 的类型提供支持。The Field method provides support for accessing columns as nullable types. 如果中的基础值 DataSetValue ,则返回的可以为 null 的类型的值为 nullIf the underlying value in the DataSet is Value, the returned nullable type will have a value of null.

如果指定的值 DataColumn 为 null 并且 T 是引用类型或可以为 null 的类型,则返回类型将为 nullIf the value of the specified DataColumn is null and T is a reference type or nullable type, then the return type will be null. Field方法不会返回 ValueThe Field method will not return Value.

Field方法不执行类型转换。The Field method does not perform type conversions. 如果需要类型转换,则应首先使用方法获取列值 FieldIf 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.

适用于

Field<T>(DataRow, Int32, DataRowVersion)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, Int32, DataRowVersion) 方法还支持可以为 null 的类型。The Field<T>(DataRow, Int32, DataRowVersion) method also supports nullable types.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T Field(System::Data::DataRow ^ row, int columnIndex, System::Data::DataRowVersion version);
public static T Field<T> (this System.Data.DataRow row, int columnIndex, System.Data.DataRowVersion version);
public static T? Field<T> (this System.Data.DataRow row, int columnIndex, System.Data.DataRowVersion version);
static member Field : System.Data.DataRow * int * System.Data.DataRowVersion -> 'T
<Extension()>
Public Function Field(Of T) (row As DataRow, columnIndex As Integer, version As DataRowVersion) As T

类型参数

T

指定列的返回类型的泛型形参。A generic parameter that specifies the return type of the column.

参数

row
DataRow

输入 DataRow,作为扩展方法的 this 实例。The input DataRow, which acts as the this instance for the extension method.

columnIndex
Int32

要返回其值的列的从零开始的序号。The zero-based ordinal of the column to return the value of.

version
DataRowVersion

DataRowVersion 枚举,指定要返回的列值版本,如 CurrentOriginal 版本。A DataRowVersion enumeration that specifies the version of the column value to return, such as Current or Original version.

返回

T

ordinalversion 指定的 T 类型的 DataColumn 值。The value, of type T, of the DataColumn specified by ordinal and version.

例外

基础列的值类型无法转换为泛型参数 T 指定的类型。The value type of the underlying column could not be cast to the type specified by the generic parameter, T.

ordinal 指定的列不存在于包含 DataRowDataTable 中。The column specified by ordinal does not exist in the DataTable that the DataRow is a part of.

将“null”值赋给了不可为 null 的类型。A null value was assigned to a non-nullable type.

注解

DataSet类用类的实例表示 nullValue DBNullThe DataSet class represents null values with the Value instance of the DBNull class. Language-Integrated 查询 (LINQ) 表达式,该表达式访问包含 null 值的列时,将 InvalidCastException 在运行时生成。A Language-Integrated Query (LINQ) expression that accessed a column with a null value would generate a InvalidCastException at run time. 此外, DataSet 不支持可以为 null 的类型。Additionally, DataSet doesn't support nullable types. Field方法为将列访问为可以为 null 的类型提供支持。The Field method provides support for accessing columns as nullable types. 如果中的基础值 DataSetValue ,则返回的可以为 null 的类型的值为 nullIf the underlying value in the DataSet is Value, the returned nullable type will have a value of null.

如果指定的值 DataColumn 为 null 并且 T 是引用类型或可以为 null 的类型,则返回类型将为 nullIf the value of the specified DataColumn is null and T is a reference type or nullable type, then the return type will be null. Field方法不会返回 ValueThe Field method will not return Value.

Field方法不执行类型转换。The Field method does not perform type conversions. 如果需要类型转换,则应首先使用方法获取列值 FieldIf 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.

适用于

Field<T>(DataRow, String, DataRowVersion)

为指定行中的每个列值提供强类型访问。Provides strongly-typed access to each of the column values in the specified row. Field<T>(DataRow, String, DataRowVersion) 方法还支持可以为 null 的类型。The Field<T>(DataRow, String, DataRowVersion) method also supports nullable types.

public:
generic <typename T>
[System::Runtime::CompilerServices::Extension]
 static T Field(System::Data::DataRow ^ row, System::String ^ columnName, System::Data::DataRowVersion version);
public static T Field<T> (this System.Data.DataRow row, string columnName, System.Data.DataRowVersion version);
public static T? Field<T> (this System.Data.DataRow row, string columnName, System.Data.DataRowVersion version);
static member Field : System.Data.DataRow * string * System.Data.DataRowVersion -> 'T
<Extension()>
Public Function Field(Of T) (row As DataRow, columnName As String, version As DataRowVersion) As T

类型参数

T

指定列的返回类型的泛型形参。A generic parameter that specifies the return type of the column.

参数

row
DataRow

输入 DataRow,作为扩展方法的 this 实例。The input DataRow, which acts as the this instance for the extension method.

columnName
String

要返回其值的列名称。The name of the column to return the value of.

version
DataRowVersion

DataRowVersion 枚举,指定要返回的列值版本,如 CurrentOriginal 版本。A DataRowVersion enumeration that specifies the version of the column value to return, such as Current or Original version.

返回

T

columnNameversion 指定的 T 类型的 DataColumn 值。The value, of type T, of the DataColumn specified by columnName and version.

例外

基础列的值类型无法转换为泛型参数 T 指定的类型。The value type of the underlying column could not be cast to the type specified by the generic parameter, T.

columnName 指定的列不存在于包含 DataRowDataTable 中。The column specified by columnName does not exist in the DataTable that the DataRow is a part of.

将“null”值赋给了不可为 null 的类型。A null value was assigned to a non-nullable type.

注解

DataSet类用类的实例表示 nullValue DBNullThe DataSet class represents null values with the Value instance of the DBNull class. Language-Integrated 查询 (LINQ) 表达式,该表达式访问包含 null 值的列时,将 InvalidCastException 在运行时生成。A Language-Integrated Query (LINQ) expression that accessed a column with a null value would generate a InvalidCastException at run time. 此外, DataSet 不支持可以为 null 的类型。Additionally, DataSet doesn't support nullable types. Field方法为将列访问为可以为 null 的类型提供支持。The Field method provides support for accessing columns as nullable types. 如果中的基础值 DataSetValue ,则返回的可以为 null 的类型的值为 nullIf the underlying value in the DataSet is Value, the returned nullable type will have a value of null.

如果指定的值 DataColumn 为 null 并且 T 是引用类型或可以为 null 的类型,则返回类型将为 nullIf the value of the specified DataColumn is null and T is a reference type or nullable type, then the return type will be null. Field方法不会返回 ValueThe Field method will not return Value.

Field方法不执行类型转换。The Field method does not perform type conversions. 如果需要类型转换,则应首先使用方法获取列值 FieldIf 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.

适用于