Executing a Query That Returns Multiple Result Sets with DataSet : SqlCommand Select « ADO.Net « C# / CSharp Tutorial






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;
            foreach (DataTable dt in ds.Tables){
                Console.WriteLine("Result set: {0}", ++rsNumber);
                foreach (DataRow row in dt.Rows){
                    Console.WriteLine("{0}, {1}, {2}", row[0], row[1], row[2]);
                }
            }

        }
    }








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