using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class 例4_6 : System.Web.UI.Page
{
      
    protected void Page_load(object sender, EventArgs e)
    {
        string strConn = "server=(local);database=dbbook;User ID=sa;Pwd=sa1234";
        SqlConnection con = new SqlConnection(strConn);
        string sql = "select * from book order by book_id";
        SqlDataAdapter da = new SqlDataAdapter(sql,con );
        DataSet myds = new DataSet();
        da.Fill(myds, "book");
        Response.Write("<B>DataSet使用举例：</B><br/>");
        Response.Write("<Table border='1'><Tr align='center'>");
        for (int i = 0; i <= myds.Tables["book"].Columns.Count - 1; i++)
        {
            Response.Write("<td>" + myds.Tables["book"].Columns[i].Caption + "</td>");

        }
        Response.Write("</Tr>");
        for (int i = 0; i <= myds.Tables["book"].Rows.Count - 1; i++)
        {
            Response.Write("<Tr align='center'>");
            for (int j = 0; j <= myds.Tables["book"].Columns.Count - 1; j++)
            {
                Response.Write("<td>" + myds.Tables["book"].Rows[i][j] + "</td>");
            }
            Response.Write("</tr>");
        }
        Response.Write("</table>");
    }

}
