用do while实现多个结果集的查询
protected void Button1_Click(object sender, EventArgs e)
{
string constr = @"Data source=PC-20121107KEFI\MSAS;initial catalog=zhucedenglu; user id=sa; password=12345";
using (SqlConnection conn = new SqlConnection(constr)) {
conn.Open();
using (SqlCommand cmd = conn.CreateCommand()) {
cmd.CommandText = "select * from T_zhmm;select * from T_denglu";
using (SqlDataReader reader = cmd.ExecuteReader()) {
do
{
while (reader.Read())
{
TableRow tr = new TableRow();TableCell tc;
for (int i = 0;i<reader.FieldCount; i++)
{
tc = new TableCell();
tc.Text = reader.GetValue(i).ToString();
tr.Cells.Add(tc);
}
Table1.Rows.Add(tr);
}
}
while (reader.NextResult());
}
}
}
}
{
string constr = @"Data source=PC-20121107KEFI\MSAS;initial catalog=zhucedenglu; user id=sa; password=12345";
using (SqlConnection conn = new SqlConnection(constr)) {
conn.Open();
using (SqlCommand cmd = conn.CreateCommand()) {
cmd.CommandText = "select * from T_zhmm;select * from T_denglu";
using (SqlDataReader reader = cmd.ExecuteReader()) {
do
{
while (reader.Read())
{
TableRow tr = new TableRow();TableCell tc;
for (int i = 0;i<reader.FieldCount; i++)
{
tc = new TableCell();
tc.Text = reader.GetValue(i).ToString();
tr.Cells.Add(tc);
}
Table1.Rows.Add(tr);
}
}
while (reader.NextResult());
}
}
}
}