You can save code by piling SQL statements into one SqlCommand and then getting a DataReader with multiple result sets. This code shows you how to run through these.
/*
using System.Data;
using System.Data.SqlClient;
*/
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["con"]);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT TOP 3 * FROM Employees ORDER BY LastName;SELECT TOP 3 * FROM Employees ORDER BY LastName DESC",con);
SqlDataReader dr = cmd.ExecuteReader();
do {
while(dr.Read()) {
System.Diagnostics.Debug.WriteLine(dr["LastName"]);
}
} while(dr.NextResult());
con.Close();
Comments