多个结果集的查询(使用table显示多个结果集)
string connstr = "data source=WIN-10AFVI27V7T;initial catalog=School;user id=sa;password=admin;";
using (SqlConnection conn = new SqlConnection(connstr))
{
string sql = "select * from T_Class;select * from T_Student";
using (SqlCommand cmd = new SqlCommand(sql, conn))
{
conn.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
do
{
if (reader.HasRows)
{
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
Response.Write(reader.GetValue(i));
}
Response.Write("<br/>");
}
}
}
while (reader.NextResult());
}
}
}