多个结果集的查询(使用table显示多个结果集)
2012-11-27 21:32
232 查看
前台:
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="Table1" runat="server">
</asp:Table>
</div>
</form>
</body>
后台:
protected void Page_Load(object sender, EventArgs e)
{
string constr = "data source=.;initial catalog=MySchool;User ID=sa;Password=111111";
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())
{
do
{
if (reader.HasRows)
{
while (reader.Read())
{
TableRow trRow = new TableRow();
TableCell tcCell;
for (int i = 0; i < reader.FieldCount; i++)
{
tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(i).ToString();
trRow.Cells.Add(tcCell);
}
Table1.Rows.Add(trRow);
}
}
} while (reader.NextResult());
}
}
}
}
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="Table1" runat="server">
</asp:Table>
</div>
</form>
</body>
后台:
protected void Page_Load(object sender, EventArgs e)
{
string constr = "data source=.;initial catalog=MySchool;User ID=sa;Password=111111";
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())
{
do
{
if (reader.HasRows)
{
while (reader.Read())
{
TableRow trRow = new TableRow();
TableCell tcCell;
for (int i = 0; i < reader.FieldCount; i++)
{
tcCell = new TableCell();
tcCell.BorderStyle = BorderStyle.Solid;
tcCell.BorderWidth = 1;
tcCell.Text = reader.GetValue(i).ToString();
trRow.Cells.Add(tcCell);
}
Table1.Rows.Add(trRow);
}
}
} while (reader.NextResult());
}
}
}
}
相关文章推荐
- 使用valuelist实现查询结果集的分页显示
- MyBatis使用Collection查询多对多或一对多结果集bug
- 使用脚本控制网页Table的显示隐藏(全代码)_AX
- 使用json实现查询条件传回Action进行hql语句拼接查询实现在结果中查询功能在datagrid中显示查询结果
- asp.net 中使用1个DataGrid控件,显示不同表查询的结果的方法。
- hibernate使用原生SQL查询返回结果集的处理
- 查询数据库的数据,是个比较费时的工作,在使用线程查询的时候显示个进度条,并允许终止查询的实现
- yii2中,视图中使用autocomplete在传值和显示在两个不同的表的时候,进行搜索查询的方法
- Mysql使用navicat 结果集部分未显示
- Hibernate分页查询oracle数据库显示结果集与实际查询不匹配
- 使用plsql查询数据显示为乱码解决方案
- php学习笔记(二十三)PDO的预处理语句的查询以及结果集的使用
- ireport5.6使用table组件,如何用table显示javaBean数据源
- Bootstrap Table 实现简单的查询和显示功能
- 如何使用 ASP.NET查询和显示 Excel 数据
- Hibernate查询,返回new对象(注意这个新定义的类要有构造函数),使用sql带条件分页查询并且把结果显示到一个对象的集里面的解决方案
- 使用MySqlHelper类查询并显示数据
- 使用ExecuteReader返回DataReader既有查询结果集又有输出参数和返回值的使用注意事项
- MyBatis使用Collection查询多对多或一对多结果集bug
- QQZiFramework笔记:entityTable与erp.public.js使用进阶(查询条件、自定义行显示)