Using DataReader to Retrieve Schema Information

The DataReader can be used to retrieve schema information using the SqlDataReader.GetSchemaTable() method. This method returns a DataTable that is populated with information about a resultset’s columns. Therefore, each row in this schema resultset represents a column in the actual resultset. The schema row contains information about the column, such as its name, uniqueness, data type, and more. Listing 19.11 illustrates using this method.

Listing 19.11. Retrieving Schema Information
1: program schemaquery; 2: 3: {$APPTYPE CONSOLE} 4: 5: {%DotNetAssemblyCompiler 'C:\windows\microsoft.net\framework\v1.1.4322\System.Data.dll'} 6: 7: uses 8: SysUtils, 9: System.Data, 10: System.Data.SqlClient, 11: System.Collections; ...

Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.