ITeye博客

输出多个结果集

mywebcode · 2012-11-29 21:11 · Markdown

ado一次输出多个结果集

string constr = "data source=.;initial catalog=TestSchool;user id=sa;password=7777777";
using(SqlConnection conn=new SqlConnection(constr))
{
string sql = "select * from MyStudents;select * from class";
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).ToString()+" ");
}
Response.Write("<br>");
}
}

}
while (reader.NextResult());

}
}
}
}
}
}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。