SqlDataReader.GetSchemaTable SqlDataReader.GetSchemaTable SqlDataReader.GetSchemaTable SqlDataReader.GetSchemaTable Method

定义

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

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

返回

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

实现

异常

注解

GetSchemaTable对于方法,按以下顺序返回有关每个列的元数据:For the GetSchemaTable method returns metadata about each column in the following order:

DataReader 列DataReader column 说明Description
AllowDBNullAllowDBNull 如果使用者可以将列设置为 null 值,则设置为; 如果访问接口无法确定使用者是否可以将该列设置为 null 值,则设置。Set 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. 否则,则不设置。Otherwise, not set. 列可能包含空值,即使它不能设置为 null 值也是如此。A column may contain null values, even if it cannot be set to a null value.
BaseCatalogNameBaseCatalogName 包含该列的数据存储区中的目录的名称。The name of the catalog in the data store that contains the column. 如果无法确定基本目录名称,则为 NULL。NULL if the base catalog name cannot be determined. 此列的默认值为 null 值。The default of this column is a null value.
BaseColumnNameBaseColumnName 数据存储区中列的名称。The name of the column in the data store. 如果使用了别名,则该名称可能不同于列名称返回的列名称。This might be different than 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.
BaseSchemaNameBaseSchemaName 数据存储中包含该列的架构的名称。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.
BaseServerNameBaseServerName 使用的 Microsoft SQL Server 实例的名称SqlDataReaderThe name of the instance of Microsoft SQL Server used by the SqlDataReader.
BaseTableNameBaseTableName 包含该列的数据存储区中的表或视图的名称。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.
列名ColumnName 列的名称;这可能不是唯一的。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 从零开始的列序号。The zero-based ordinal of the column. 此列不能包含 null 值。This column cannot contain a null value.
ColumnSizeColumnSize 列中的值的最大可能长度。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. 对于nvarchar(MAX)存储varchar(MAX)在 SQL Server varbinary(MAX)数据库中的、和列,最大大小为2gb。For nvarchar(MAX), varchar(MAX), and varbinary(MAX) columns stored in a SQL Server database, the maximum size is 2GB. 如果以文件的形式存储和访问这些列,则文件系统会施加最大大小限制。If these columns are stored and accessed as files, the limit on maximum size is imposed by the file system. 在连接字符串中使用关键字Type System Version时,此值会发生更改。This value changes when using the Type System Version keyword in the connection string. 对于新类型,它们表示为下级类型。For new types they are represented as downlevel types. MAX 数据类型返回的普通4k 为nvarcharvarchar8000。The MAX data types return the normal 4k for nvarchar and 8000 for varchar. 有关详细信息,请参阅transact-sql 参考For more information, see the Transact-SQL reference.
DataTypeNameDataTypeName 返回表示指定列的数据类型的字符串。Returns a string representing the data type of the specified column.
IsAliasedIsAliased true:列名是一个别名。true: The column name is an alias.

false:列名不是别名。false: The column name is not an alias.
IsAutoIncrementIsAutoIncrement true:列按固定的增量将值分配给新行。true: The column assigns values to new rows in fixed increments.

false:列不会以固定增量向新行赋值。false: The column does not assign values to new rows in fixed increments. 此列的默认值为falseThe default of this column is false.
IsColumnSetIsColumnSet true:列是一个稀疏列,它是列集的成员。true: The column is a sparse column that is a member of a column set.
IsExpressionIsExpression true:列是表达式。true: The column is an expression.

false:列不是表达式。false: The column is not an expression.
IsHiddenIsHidden true:列处于隐藏状态。true: The column is hidden.

false:列不隐藏。false: The column is not hidden.
IsIdentityIsIdentity true:列为标识列。true: The column is an identity column.

false:列不是标识列。false: The column is not an identity column.
IsKeyIsKey true:此列是行集中的一组列中的一组列,这些列一起使用,可唯一地标识行。true: The column is one of a set of columns in the rowset that, taken together, uniquely identify the row. IsKey设置为true的一组列必须唯一标识行集中的一行。The set of columns with IsKey set to 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.

false:列不需要唯一地标识行。false: The column is not required to uniquely identify the row.
IsLongIsLong true:列包含二进制长对象(BLOB),其中包含非常长的数据。true: The column contains a Binary Long Object (BLOB) that contains very long data. 非常长数据的定义是特定于提供程序的。The definition of very long data is provider-specific.

false:列不包含包含非常长数据的二进制长对象(BLOB)。false: The column does not contain a Binary Long Object (BLOB) that contains very long data.
为只读IsReadOnly true:无法修改列。true: The column cannot be modified.

false:可以修改列。false: The column can be modified.
IsRowVersionIsRowVersion true:列包含不能写入的持久性行标识符,并且除了标识该行以外,没有有意义的值。true: The column contains a persistent row identifier that cannot be written to, and has no meaningful value except to identity the row.

false:此列不包含不能写入的永久性行标识符,并且除了标识该行以外,没有有意义的值。false: The column does not contain a persistent row identifier that cannot be written to, and has no meaningful value except to identity the row.
IsUniqueIsUnique true:列的类型timestamp为。true: Column is of type timestamp.

false:列的类型timestamp不是。false: Column is not of type timestamp.
NonVersionedProviderTypeNonVersionedProviderType 列的类型,而不考虑在连接Type System Version字符串中指定的当前。The type of the column irrespective of the current Type System Version specified in the connection string. 返回的值来自SqlDbType枚举。The returned value is from the SqlDbType enumeration.
NumericPrecisionNumericPrecision 如果ProviderType是数值数据类型,则这是列的最大精度。If ProviderType is a numeric data type, this is the maximum precision of the column. 精度取决于该列的定义。The precision depends on the definition of the column. 如果ProviderType不是数值数据类型,则为255。If ProviderType is not a numeric data type, this is 255.
NumericScaleNumericScale 如果ProviderType为 DBTYPE_DECIMAL 或 DBTYPE_NUMERIC,则为小数点右侧的位数。If ProviderType is DBTYPE_DECIMAL or DBTYPE_NUMERIC, the number of digits to the right of the decimal point. 否则为255。Otherwise, this is 255.
ProviderSpecificDataTypeProviderSpecificDataType 基于连接字符串中的Type System Version关键字,返回列的特定于提供程序的数据类型。Returns the provider-specific data type of the column based on the Type System Version keyword in the connection string.
ProviderTypeProviderType 列的数据类型的指示器。The indicator of the column's data type. 如果列的数据类型不同于行的数据类型,则它必须是对象。If the data type of the column varies from row to row, this must be Object. 此列不能包含 null 值。This column cannot contain a null value.
UdtAssemblyQualifiedNameUdtAssemblyQualifiedName 如果该列是用户定义的类型(UDT),则这是该 UDT 的程序集的限定名称,其名称AssemblyQualifiedName为。If the column is a user-defined type (UDT), this is the qualified name of the UDT's assembly as per AssemblyQualifiedName. 如果列不是 UDT,则为 null。If the column is not a UDT, this is null.
XmlSchemaCollectionDatabaseXmlSchemaCollectionDatabase 此 XML 实例的架构集合所在的数据库的名称,如果该行包含有关 XML 列的信息。The name of the database where the schema collection for this XML instance is located, if the row contains information about an XML column. 如果在当前null数据库Nothing中定义了集合,则此值为(在 Visual Basic 中)。This value is null (Nothing in Visual Basic) if the collection is defined within the current database. 如果没有架构集合,则此方法也为 null,在这种XmlSchemaCollectionName情况XmlSchemaCollectionOwningSchema下,和列也为 null。It is also null if there is no schema collection, in which case the XmlSchemaCollectionName and XmlSchemaCollectionOwningSchema columns are also null.
XmlSchemaCollectionNameXmlSchemaCollectionName 此 XML 实例的架构集合的名称,如果该行包含有关 XML 列的信息。The name of the schema collection for this XML instance, if the row contains information about an XML column. 如果没有关联nullNothing架构集合,则此值为(在 Visual Basic 中)。This value is null (Nothing in Visual Basic) if there is no associated schema collection. 如果该值为 null,则XmlSchemaCollectionDatabaseXmlSchemaCollectionOwningSchema列也为 null。If the value is null, the XmlSchemaCollectionDatabase and XmlSchemaCollectionOwningSchema columns are also null.
XmlSchemaCollectionOwningSchemaXmlSchemaCollectionOwningSchema 此 XML 实例的架构集合所在的所属关系架构。如果该行包含有关 XML 列的信息,则为。The owning relational schema where the schema collection for this XML instance is located, if the row contains information about an XML column. 如果在当前null数据库Nothing中定义了集合,则此值为(在 Visual Basic 中)。This value is null (Nothing in Visual Basic) if the collection is defined within the current database. 如果没有架构集合,则此方法也为 null,在这种XmlSchemaCollectionDatabase情况XmlSchemaCollectionName下,和列也为 null。It is also null if there is no schema collection, in which case the XmlSchemaCollectionDatabase and XmlSchemaCollectionName columns are also null.

备注

若要确保 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.

适用于

另请参阅