---
title: "输出多个结果集"
author: "mywebcode"
date: "2012-11-29T21:11:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2013-05-08T10:26:25Z"
id: 1862860
url: "https://mywebcode.iteye.com/blog/1862860"
---

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 &lt; reader.FieldCount; i++)  
{  
Response.Write(reader.GetValue(i).ToString()+" ");  
}  
Response.Write("&lt;br&gt;");  
}  
}

}  
while (reader.NextResult());

}  
}  
}  
}  
}  
}