SqlDataReader.GetSchemaTable 方法

定義

傳回 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 值,即使它不得設定為 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. 如果使用了別名,這可能會與 ColumnName 資料行中傳回的資料行名稱不同。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 SqlDataReader所使用之 Microsoft SQL Server 實例的名稱。The 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.
ColumnNameColumnName 資料行的名稱;這可能不是唯一的。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. 對於儲存在 SQL Server 資料庫中 nvarchar(MAX)varchar(MAX)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 資料類型會針對 varchar傳回 nvarchar 和8000的一般4k。The MAX data types return the normal 4k for nvarchar and 8000 for varchar. 如需詳細資訊,請參閱transact-sql 參考For more information, see the Transact-SQL reference.
D m eDataTypeName 傳回字串,表示指定之資料行的資料類型。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.
IsReadOnlyIsReadOnly 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:資料行的類型為 timestamptrue: Column is of type timestamp.

false:資料行不是 timestamp的類型。false: Column is not of type timestamp.
NonVersionedProviderTypeNonVersionedProviderType 資料行的類型,而不論連接字串中指定的目前 Type System VersionThe 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 之元件的限定名稱,依據 AssemblyQualifiedNameIf 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 (在 Visual Basic 中Nothing)。This value is null (Nothing in Visual Basic) if the collection is defined within the current database. 如果沒有架構集合,這也是 null,在此情況下,XmlSchemaCollectionNameXmlSchemaCollectionOwningSchema 資料行也會是 null。It is also null if there is no schema collection, in which case the XmlSchemaCollectionName and XmlSchemaCollectionOwningSchema columns are also null.
Xmlschemacollectionname namespace-uriXmlSchemaCollectionName 這個 XML 實例的架構集合名稱(如果資料列包含 XML 資料行的相關資訊)。The name of the schema collection for this XML instance, if the row contains information about an XML column. 如果沒有相關聯的架構集合,則這個值會 null (在 Visual Basic 中Nothing)。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 (在 Visual Basic 中Nothing)。This value is null (Nothing in Visual Basic) if the collection is defined within the current database. 如果沒有架構集合,這也是 null,在此情況下,XmlSchemaCollectionDatabaseXmlSchemaCollectionName 資料行也會是 null。It is also null if there is no schema collection, in which case the XmlSchemaCollectionDatabase and XmlSchemaCollectionName columns are also null.

注意

若要確保中繼資料資料行傳回正確的資訊,您必須呼叫 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.

適用於

另請參閱