Редагувати

Поділитися через


SqlDataReader.GetSchemaTable Method

Definition

Returns a DataTable that describes the column metadata of the SqlDataReader.

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

Returns

A DataTable that describes the column metadata.

Implements

Exceptions

Remarks

The GetSchemaTable method returns the following metadata about each column:

DataReader column Description
AllowDBNull 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. A column may contain null values, even if it cannot be set to a null value.
BaseCatalogName The name of the catalog in the data store that contains the column. NULL if the base catalog name cannot be determined. The default of this column is a null value.
BaseColumnName 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. 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. The default of this column is a null value.
BaseSchemaName The name of the schema in the data store that contains the column. A null value if the base schema name cannot be determined. The default of this column is a null value.
BaseServerName The name of the instance of Microsoft SQL Server used by the SqlDataReader.
BaseTableName The name of the table or view in the data store that contains the column. A null value if the base table name cannot be determined. The default of this column is a null value.
ColumnName The name of the column; this might not be unique. 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.
ColumnOrdinal The zero-based ordinal of the column. This column cannot contain a null value.
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. 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. This value changes when using the Type System Version keyword in the connection string. For new types they are represented as downlevel types. The MAX data types return the normal 4k for nvarchar and 8000 for varchar. For more information, see the Transact-SQL reference.
DataTypeName Returns a string representing the data type of the specified column.
IsAliased true: The column name is an alias.

false: The column name is not an alias.
IsAutoIncrement true: The column assigns values to new rows in fixed increments.

false: The column does not assign values to new rows in fixed increments. The default of this column is false.
IsColumnSet true: The column is a sparse column that is a member of a column set.
IsExpression true: The column is an expression.

false: The column is not an expression.
IsHidden true: The column is hidden.

false: The column is not hidden.
IsIdentity true: The column is an identity column.

false: The column is not an identity column.
IsKey true: The column is one of a set of columns in the rowset that, taken together, uniquely identify the row. 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: The column is not required to uniquely identify the row.
IsLong true: The column contains a Binary Long Object (BLOB) that contains very long data. The definition of very long data is provider-specific.

false: The column does not contain a Binary Long Object (BLOB) that contains very long data.
IsReadOnly true: The column cannot be modified.

false: The column can be modified.
IsRowVersion true: The column contains a persistent row identifier that cannot be written to, and has no meaningful value except to identity the row.

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.
IsUnique true: Column is of type timestamp.

false: Column is not of type timestamp.
NonVersionedProviderType The type of the column irrespective of the current Type System Version specified in the connection string. The returned value is from the SqlDbType enumeration.
NumericPrecision If ProviderType is a numeric data type, this is the maximum precision of the column. The precision depends on the definition of the column. If ProviderType is not a numeric data type, this is 255.
NumericScale If ProviderType is DBTYPE_DECIMAL or DBTYPE_NUMERIC, the number of digits to the right of the decimal point. Otherwise, this is 255.
ProviderSpecificDataType Returns the provider-specific data type of the column based on the Type System Version keyword in the connection string.
ProviderType The indicator of the column's data type. If the data type of the column varies from row to row, this must be Object. This column cannot contain a null value.
UdtAssemblyQualifiedName If the column is a user-defined type (UDT), this is the qualified name of the UDT's assembly as per AssemblyQualifiedName. If the column is not a UDT, this is null.
XmlSchemaCollectionDatabase The name of the database where the schema collection for this XML instance is located, if the row contains information about an XML column. This value is null (Nothing in Visual Basic) if the collection is defined within the current database. It is also null if there is no schema collection, in which case the XmlSchemaCollectionName and XmlSchemaCollectionOwningSchema columns are also null.
XmlSchemaCollectionName The name of the schema collection for this XML instance, if the row contains information about an XML column. This value is null (Nothing in Visual Basic) if there is no associated schema collection. If the value is null, the XmlSchemaCollectionDatabase and XmlSchemaCollectionOwningSchema columns are also null.
XmlSchemaCollectionOwningSchema The owning relational schema where the schema collection for this XML instance is located, if the row contains information about an XML column. This value is null (Nothing in Visual Basic) if the collection is defined within the current database. It is also null if there is no schema collection, in which case the XmlSchemaCollectionDatabase and XmlSchemaCollectionName columns are also null.

Note

To make sure that metadata columns return the correct information, you must call ExecuteReader with the behavior parameter set to KeyInfo. Otherwise, some of the columns in the schema table may return default, null, or incorrect data.

Applies to

See also