Schema Table from SqlDataReader : SqlDataReader « ADO.Net « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » ADO.Net » SqlDataReader 
32.26.21.Schema Table from SqlDataReader
using System;
using System.Data;
using System.Data.SqlClient;

    class SchemaTable
    {
        static void Main(string[] args)
        {
            string connString = @"server = .\sqlexpress;integrated security = true;database = northwind";
            string sql = @"select * from employees";
            SqlConnection conn = new SqlConnection(connString);
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                SqlDataReader rdr = cmd.ExecuteReader();
                DataTable schema = rdr.GetSchemaTable();
                foreach (DataRow row in schema.Rows)
                {
                    foreach (DataColumn col in schema.Columns)
                        Console.WriteLine(col.ColumnName + " = " + row[col]);
                }
                rdr.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error Occurred: " + e);
            }
            finally
            {
                conn.Close();
            
        }
    }
32.26.SqlDataReader
32.26.1.SqlDataReader
32.26.2.Use SQL Server Data Provider
32.26.3.Reference result set by column name in SqlDataReader
32.26.4.Reference result set by column index in SqlDataReader
32.26.5.Ordinal Indexer demo
32.26.6.Use loop to read all data in SqlDataReader
32.26.7.Use SqlDataReader to retrieve data in the resultset
32.26.8.Get data by data type using SqlDataReader
32.26.9.Using a DataReader to read row by row
32.26.10.Updating Data Using CommondBuilder
32.26.11.SqlDataReader: RecordsAffected
32.26.12.Typed Accessors: int, varchar and decimal
32.26.13.SqlDataReader.GetString, GetDateTime
32.26.14.how to read a table schema
32.26.15.Use indexer to read data
32.26.16.Mapping .NET Data Provider Data Types to .NET Framework Data Types by calling the GetXXX method
32.26.17.Mapping .NET Data Provider Data Types to .NET Framework Data Types by casting
32.26.18.Mapping .NET Data Provider Data Types to .NET Framework Data Types by converting
32.26.19.Retrieving a Result Set Stream Using a DataReader
32.26.20.Retrieves data as native SQL Server types.
32.26.21.Schema Table from SqlDataReader
32.26.22.ResultSet Info
32.26.23.Output fields from DataReader row
32.26.24.Ordinal Indexer
32.26.25.Get the column ordinal for the Phone attribute and use it to output the column
32.26.26.Data Reading with SqlDataReader
32.26.27.Accessing Data Values in a DataReader
32.26.28.DataReader has records using HasRows property
32.26.29.Handle Multiple Results
32.26.30.Determining the Number of Records Returned in a DataReader
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.