using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
namespace _11_26
{
public partial class lianxi2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string constr = "data source=.\\SQLEXPRESSPC;initial catalog=School;user id=sa;password=admin";
using (SqlConnection con = new SqlConnection(constr))
{
string sql = "select * from Student;select * from Class";
using (SqlCommand cmd = new SqlCommand(sql, con))
{
con.Open();
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader.HasRows)
{
#region 读取多个结果集的方法
//do-----while,do中先来读取第一个结果集,while(reader.NextResult())中判断是否还有结果集,如果有在do中再次读取第二个结果集,一次类推------
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());
#endregion
#region 读取一个结果集的方法
//while (reader.Read())
//{
// //内层循环获取列
// for (int i = 0; i < reader.FieldCount; i++)
// {
// Response.Write(reader.GetValue(i));
// }
// Response.Write("<br>");
//}
#endregion
}
}
}
}
}
}
}