Export (0) Print
Expand All

SqlDataReader.GetSchemaTable Method

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

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)

public override DataTable GetSchemaTable()

Return Value

Type: System.Data.DataTable
A DataTable that describes the column metadata.

Implements

IDataReader.GetSchemaTable()
IDataReader.GetSchemaTable()

ExceptionCondition
InvalidOperationException

The SqlDataReader is closed.

For the GetSchemaTable method returns metadata about each column in the following order:

DataReader column

Description

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 ordinal of the column. This is zero for the bookmark column of the row, if any. Other columns are numbered starting with one. 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 in SQL Server Books Online.

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 a null value.

NumericScale

If ProviderType is is DBTYPE_DECIMAL or DBTYPE_NUMERIC, the number of digits to the right of the decimal point. Otherwise, this is a null value.

IsUnique

true only for timestamp columns and false for all other columns.

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.

BaseServerName

The name of the instance of Microsoft SQL Server used by the SqlDataReader.

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.

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.

DataType

Maps to the .NET Framework type of the column.

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.

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.

IsAliased

true if the column name is an alias; otherwise false.

IsExpression

true if the column is an expression; otherwise false.

IsIdentity

true if the column is an identity column; otherwise false.

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.

IsRowVersion

Set if the column contains a persistent row identifier that cannot be written to, and has no meaningful value except to identity the row.

IsHidden

true if the column is hidden; otherwise false.

IsLong

Set if the column contains a Binary Long Object (BLOB) that contains very long data. The definition of very long data is provider-specific.

IsReadOnly

true if the column cannot be modified; otherwise false.

ProviderSpecificDataType

Returns the provider-specific data type of the column based on the Type System Version keyword in the connection string.

DataTypeName

Returns a string representing the data type of the specified column.

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.

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.

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.

NoteNote:

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.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft