OleDbDataReader.GetSchemaTable 方法

定义

返回一个 DataTable,它描述 OleDbDataReader 的列元数据。Returns a DataTable that describes the column metadata of the OleDbDataReader.

public:
 virtual System::Data::DataTable ^ GetSchemaTable();
public System.Data.DataTable GetSchemaTable ();
override this.GetSchemaTable : unit -> System.Data.DataTable
Public Function GetSchemaTable () As DataTable

返回

一个描述列元数据的 DataTableA DataTable that describes the column metadata.

异常

注解

方法映射到 OLE DB IColumnsRowset:: GetColumnsRowset方法,并按以下顺序返回有关每个列的元数据: GetSchemaTableThe GetSchemaTable method maps to the OLE DB IColumnsRowset::GetColumnsRowset method, and returns metadata about each column in the following order:

DataReader 列DataReader column OLE DB 列 IDOLE DB column ID 说明Description
列名ColumnName DBCOLUMN_NAMEDBCOLUMN_NAME 列的名称;这可能不是唯一的。The name of the column; this might not be unique. 如果无法确定此值,则返回 null 值。If this cannot be determined, a null value is returned. 此名称始终反映当前视图或命令文本中列的最近重命名。This name always reflects the most recent renaming of the column in the current view or command text.
ColumnOrdinalColumnOrdinal DBCOLUMN_NUMBERDBCOLUMN_NUMBER 从零开始的列序号。The zero-based ordinal of the column. 此列不能包含 null 值。This column cannot contain a null value.
ColumnSizeColumnSize DBCOLUMN_COLUMNSIZEDBCOLUMN_COLUMNSIZE 列中的值的最大可能长度。The maximum possible length of a value in the column. 对于使用固定长度数据类型的列,这是数据类型的大小。For columns that use a fixed-length data type, this is the size of the data type.
NumericPrecisionNumericPrecision DBCOLUMN_PRECISIONDBCOLUMN_PRECISION 如果 DbType 为数值数据类型,则这是列的最大精度。If DbType is a numeric data type, this is the maximum precision of the column. 数据类型为 DBTYPE_DECIMAL 或 DBTYPE_NUMERIC 的列的精度取决于该列的定义。The precision of columns with a data type of DBTYPE_DECIMAL or DBTYPE_NUMERIC depends on the definition of the column. 如果 DbType 不是数值数据类型,则此值为 null 值。If DbType is not a numeric data type, this is a null value.
NumericScaleNumericScale DBCOLUMN_SCALEDBCOLUMN_SCALE 如果 DbType 为 DBTYPE_DECIMAL 或 DBTYPE_NUMERIC,则为小数点右侧的位数。If DbType is DBTYPE_DECIMAL or DBTYPE_NUMERIC, this is the number of digits to the right of the decimal point. 否则,此值为 null 值。Otherwise, this is a null value.
数据类型DataType NoneNone 映射到列的 .NET Framework 类型。Maps to the .NET Framework type of the column.
ProviderTypeProviderType DBCOLUMN_TYPEDBCOLUMN_TYPE 列的数据类型的指示器。The indicator of the column's data type. 如果列的数据类型不同于行的数据类型,则必须为 DBTYPE_VARIANT。If the data type of the column varies from row to row, this must be DBTYPE_VARIANT. 此列不能包含 null 值。This column cannot contain a null value.
IsLongIsLong DBCOLUMNFLAGS_ISLONGDBCOLUMNFLAGS_ISLONG 如果列包含一个包含非常长数据的二进制长对象(BLOB),则提供程序设置 DBCOLUMNFLAGS_ISLONG。The provider sets DBCOLUMNFLAGS_ISLONG if the column contains a Binary Long Object (BLOB) that contains very long data. 非常长数据的定义是特定于提供程序的。The definition of very long data is provider-specific. 此标志的设置对应于数据类型的 PROVIDER_TYPES 行集中的 IS_LONG 列的值。The setting of this flag corresponds to the value of the IS_LONG column in the PROVIDER_TYPES rowset for the data type.
AllowDBNullAllowDBNull DBCOLUMNFLAGS_ISNULLABLEDBCOLUMNFLAGS_ISNULLABLE 如果使用者可以将列设置为 null 值,或者如果访问接口无法确定使用者是否可以将该列设置为 null 值,则提供程序设置 DBCOLUMNFLAGS_ISNULLABLE。The provider sets DBCOLUMNFLAGS_ISNULLABLE if the consumer can set the column to a null value, or if the provider cannot determine whether the consumer can set the column to a null value. 列可能包含空值,即使它不能设置为 null 值也是如此。A column may contain null values, even if it cannot be set to a null value.
为只读IsReadOnly DBCOLUMNFLAGS_WRITEDBCOLUMNFLAGS_WRITE true如果无法修改列,则为;否则false为。true if the column cannot be modified; otherwise false. 如果提供程序设置了 DBCOLUMNFLAGS_WRITE 或 DBCOLUMNFLAGS_WRITEUNKNOWN 标志,则假定列可写。The column is assumed to be writable if the provider has set either the DBCOLUMNFLAGS_WRITE or DBCOLUMNFLAGS_WRITEUNKNOWN flag.
IsRowVersionIsRowVersion DBCOLUMNFLAGS_ISROWIDDBCOLUMNFLAGS_ISROWID 如果列包含不能写入的永久性行标识符,则该提供程序将设置 DBCOLUMNFLAGS_ISROWID,并且除了标识该行以外,它还没有有意义的值。The provider sets DBCOLUMNFLAGS_ISROWID if the column contains a persistent row identifier that cannot be written to, and has no meaningful value except to identity the row.
IsUniqueIsUnique DBCOLUMN_ISUNIQUEDBCOLUMN_ISUNIQUE VARIANT_TRUE:基表中没有两行(在 BaseTableName 中返回的表)可以在此列中具有相同的值。VARIANT_TRUE: No two rows in the base table-the table returned in BaseTableName-can have the same value in this column. 如果列本身表示键,或如果存在仅适用于此列的 UNIQUE 类型的约束,则可以保证 IsUnique 为 VARIANT_TRUE。IsUnique is guaranteed to be VARIANT_TRUE if the column represents a key by itself or if there is a constraint of type UNIQUE that applies only to this column.

VARIANT_FALSE:列可以包含基表中的重复值。VARIANT_FALSE: The column can contain duplicate values in the base table. 此列的默认值为 VARIANT_FALSE。The default of this column is VARIANT_FALSE.
IsKeyIsKey DBCOLUMN_KEYCOLUMNDBCOLUMN_KEYCOLUMN VARIANT_TRUE:此列是行集中的一组列中的一组列,这些列一起使用,可唯一地标识行。VARIANT_TRUE: The column is one of a set of columns in the rowset that, taken together, uniquely identify the row. IsKey 设置为 VARIANT_TRUE 的一组列必须唯一地标识行集中的一行。The set of columns with IsKey set to VARIANT_TRUE must uniquely identify a row in the rowset. 不要求这组列是最少的一组列。There is no requirement that this set of columns is a minimal set of columns. 这组列可以从基表主键、唯一约束或唯一索引生成。This set of columns may be generated from a base table primary key, a unique constraint or a unique index.

VARIANT_FALSE:列不需要唯一地标识行。VARIANT_FALSE: The column is not required to uniquely identify the row.
IsAutoIncrementIsAutoIncrement DBCOLUMN_ISAUTOINCREMENTDBCOLUMN_ISAUTOINCREMENT VARIANT_TRUE:列按固定的增量将值分配给新行。VARIANT_TRUE: The column assigns values to new rows in fixed increments.

VARIANT_FALSE:列不会以固定增量向新行赋值。VARIANT_FALSE: The column does not assign values to new rows in fixed increments. 此列的默认值为 VARIANT_FALSE。The default of this column is VARIANT_FALSE.
BaseSchemaNameBaseSchemaName DBCOLUMN_BASESCHEMANAMEDBCOLUMN_BASESCHEMANAME 数据存储中包含该列的架构的名称。The name of the schema in the data store that contains the column. 如果无法确定基本架构名称,则为 null 值。A null value if the base schema name cannot be determined. 此列的默认值为 null 值。The default of this column is a null value.
BaseCatalogNameBaseCatalogName DBCOLUMN_BASECATALOGNAMEDBCOLUMN_BASECATALOGNAME 包含该列的数据存储区中的目录的名称。The name of the catalog in the data store that contains the column. 如果无法确定基本目录名称,则为 null 值。A null value if the base catalog name cannot be determined. 此列的默认值为 null 值。The default of this column is a null value.
BaseTableNameBaseTableName DBCOLUMN_BASETABLENAMEDBCOLUMN_BASETABLENAME 包含该列的数据存储区中的表或视图的名称。The name of the table or view in the data store that contains the column. 如果无法确定基表名称,则为 null 值。A null value if the base table name cannot be determined. 此列的默认值为 null 值。The default of this column is a null value.
BaseColumnNameBaseColumnName DBCOLUMN_BASECOLUMNNAMEDBCOLUMN_BASECOLUMNNAME 数据存储区中列的名称。The name of the column in the data store. 如果使用了别名,则该名称可能不同于列名称返回的列名称。This might be different from the column name returned in the ColumnName column if an alias was used. 如果无法确定基列名称,或者如果行集列派生,但与数据存储区中的列不完全相同,则为 null 值。A null value if the base column name cannot be determined or if the rowset column is derived, but not identical to, a column in the data store. 此列的默认值为 null 值。The default of this column is a null value.

备注

若要确保 metadata 列返回正确的信息,必须在ExecuteReader behavior参数设置为KeyInfo的情况下调用。To make sure that metadata columns return the correct information, you must call ExecuteReader with the behavior parameter set to KeyInfo. 否则,架构表中的某些列可能返回默认值、null 值或不正确的数据。Otherwise, some of the columns in the schema table may return default, null, or incorrect data.

适用于

另请参阅