Retrieves a schema table for a query : DataTable « 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 » DataTable 
32.36.23.Retrieves a schema table for a query
using System;
using System.Data;
using System.Data.SqlClient;

public class GetSchema
{
    public static void Main() 
    {
        string connectionString = "Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI";
        string SQL = "SELECT * FROM CUSTOMERS";

        SqlConnection con = new SqlConnection(connectionString);
        SqlCommand cmd = new SqlCommand(SQL, con);
        SqlDataReader r;
        DataTable schema;

        con.Open();
        r = cmd.ExecuteReader();
        schema = r.GetSchemaTable();
        con.Close();
        foreach (DataRow row in schema.Rows)
        {
            foreach (DataColumn col in schema.Columns)
            {
                Console.WriteLine(col.ColumnName + " = " + row[col]);
            }
        }
    }
}
32.36.DataTable
32.36.1.Loop through DataTable by DataRow
32.36.2.Use DataTable to insert a Row
32.36.3.Add Row to DataTable
32.36.4.Accessing Data Values in a DataTable or DataSet
32.36.5.Adding Columns to DataTable
32.36.6.Adding Constraint to DataTable
32.36.7.Adding a Calculated Column to a DataTable
32.36.8.Adding a Column to a Child DataTable That Displays Data from the Parent Table
32.36.9.Adding a Column to a Parent DataTable That Aggregates a Child Table's Column Values
32.36.10.Creating a DataColumn and Adding It to a DataTable
32.36.11.Creating a DataTable and Adding It to a DataSet
32.36.12.Retrieving a Result Set Using a DataTable or a DataSet
32.36.13.Pop DataTable
32.36.14.Output Constraint Properties
32.36.15.Output the rows from the DataTable with foreach loop over DataRowCollection
32.36.16.Modify DataTable
32.36.17.Loop through the rows in DataTable
32.36.18.Creating Single- and Multi-Column Primary Keys
32.36.19.Creating a Unique Constraint
32.36.20.Append columns to DataTable
32.36.21.Accessing FirstName value in row 3 directly
32.36.22.Filter Sort
32.36.23.Retrieves a schema table for a query
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.