Multiple queries in a single SqlCommand


Continuing the discussion about ADO.NET performance I will now show you the syntax to do multiple queries inside a single SqlCommand for SQL Server. What happen is that one call will be made to the database server - and one call back (containing ALL results).

The nice thing about ADO.NET is that is stuffs everything into our dataset tables collection.

The code for this:



            string sConn = "Data Source=(local);Network Library=DBMSSOCN;Initial Catalog=Northwind;User ID=sa;Password=stefan;";
            string sSQL = "select * from products;select * from categories";
            DataSet dd = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(sConn,
                CommandType.Text, sSQL);
            dataGridView1.DataSource = dd.Tables[0];
            dataGridView2.DataSource = dd.Tables[1];

As you can see the products are put into tables[0] and categories into tables[1].