Article ID: 310107 - Last Review: July 1, 2004 - Revision: 2.3 How To Retrieve Column Schema by Using the DataReader GetSchemaTable Method and Visual C# .NET
This article was previously published under Q310107 On This PageSUMMARY This article demonstrates how to use the GetSchemaTable method of the DataReader object in ADO.NET to retrieve column schema information. Another
name for a column's schema is its field properties. Column schema information
includes the following information about the column:
Note To get the primary key information, including whether a field is part of a primary key and whether it is an AutoIncrement field, you must set the CommandBehavior value of the DataReader to CommandBehavior.KeyInfo. You can use the GetSchemaTable method with either the OLE DB .NET Provider or the SQL .NET Provider. The OleDbDataReader.GetSchemaTable method maps to the OLE DB IColumnsRowset::GetColumnsRowset method. The SqlDataReader.GetSchemaTable method does not use an OLE DB Provider layer. Of note, unless you explicitly use the GetSchemaTable method, the DataReader does not return column schema. Also, if you use GetSchemaTable to retrieve the column schema, you cannot update the DataReader. The DataReader always retrieves a read-only, forward-only stream of data from a database. When to Use the GetSchemaTable Method
Retrieve Column Schema with the OLE DB .NET ProviderThis sample lists the schema information for the columns (field properties) of the Employees table in the SQL Server Northwind database.Note that when you use the OLE DB .NET Provider, you use the GetSchemaTable method of the OleDbDataReader object.
Retrieve Column Schema with the SQL .NET ProviderThis sample lists the schema information for the columns (field properties) of the Employees table in the SQL Server Northwind database.Note that when you use the SQL .NET Provider, you use the GetSchemaTable method of the SqlDataReader object.
REFERENCES For more information about the DataReader and the GetSchemaTable method, see the following topics in the Visual Studio .NET Online
Help documentation:
Retrieving Data Using the DataReader
For additional information about using the OleDbConnection object's GetOleDbSchemaTable method to retrieve schema information, click the article number
below to view the article in the Microsoft Knowledge Base:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcontheadonetdatareader.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcontheadonetdatareader.asp) IDataReader.GetSchemaTable Method http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataIDataReaderClassGetSchemaTableTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataIDataReaderClassGetSchemaTableTopic.asp) NOTE: This topic includes a complete list of the columns in the returned DataTable. OleDbDataReader.GetSchemaTable Method http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbDataReaderClassGetSchemaTableTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataOleDbOleDbDataReaderClassGetSchemaTableTopic.asp) SqlDataReader.GetSchemaTable Method http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlDataReaderClassGetSchemaTableTopic.asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlDataReaderClassGetSchemaTableTopic.asp) 309681
(http://support.microsoft.com/kb/309681/EN-US/
)
How To Retrieve Schema Information by Using GetOleDbSchemaTable and Visual C# .NET
| Other Resources Other Support Sites
CommunityGet Help NowArticle Translations
|





















Back to the top