Executing a Query That Returns Multiple Result Sets with SqlDataReader : SqlCommand Select « 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 » SqlCommand Select 
32.21.6.Executing a Query That Returns Multiple Result Sets with SqlDataReader
using System;
using System.Data;
using System.Data.SqlClient;

    class Program
    {
        static void Main(string[] args)
        {
            string sqlConnectString = "Data Source=(local);" +
                "Integrated security=SSPI;Initial Catalog=AdventureWorks;";

            string sqlSelect = "SELECT TOP 3 * FROM Sales.SalesOrderHeader;" +
                "SELECT TOP 3 * FROM Sales.SalesOrderDetail";
            int rsNumber;
            SqlDataAdapter da = new SqlDataAdapter(sqlSelect, sqlConnectString);
            DataSet ds = new DataSet( );
            da.Fill(ds);

            rsNumber = 0;

            using (SqlConnection connection = new SqlConnection(sqlConnectString)){
                SqlCommand command = new SqlCommand(sqlSelect, connection);
                connection.Open( );
                SqlDataReader dr = command.ExecuteReader( );

                rsNumber = 0;
                do{
                    Console.WriteLine("Result set: {0}", ++rsNumber);
                    while (dr.Read( )){
                        Console.WriteLine("{0}, {1}, {2}", dr[0], dr[1], dr[2]);
                    }
                    Console.WriteLine(Environment.NewLine);
                while (dr.NextResult( ));
            }
        }
    }
32.21.SqlCommand Select
32.21.1.Simple Query
32.21.2.How to perform a SELECT statement using ADO.NET
32.21.3.Execute Scalar Example
32.21.4.Executing a Query That Does Not Return a Result Set
32.21.5.Executing a Query That Returns Multiple Result Sets with DataSet
32.21.6.Executing a Query That Returns Multiple Result Sets with SqlDataReader
32.21.7.Execute the command to get Scalar value
32.21.8.CommandReader
32.21.9.Get table list
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.