多个结果集的查询(使用table显示多个结果集)

本文深入探讨了数据库管理系统的基本概念、数据模型、实体-关系模型、索引理论、事务管理、结构化查询语言和数据库备份等核心内容,提供了一套全面的数据管理解决方案。
前台:
<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());
                    }
                }
            }
        }
 
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值