</body>
</html>
后置页面代码:
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 _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindData();
}
}
public void bindData()
{
//实例化对象
SqlConnection con = new SqlConnection();
//实例化SqlConnection对象连接数据库字符串
con.ConnectionString = "Data Source=kaerle;Initial Catalog=MyBookShop;Integrated Security=True";
//定义SQL语句
string sql = "select * from Books";
//实例化SqlDataAdapter对象
SqlDataAdapter da = new SqlDataAdapter(sql, con);
//实例化DataSet
DataSet ds = new DataSet();
da.Fill(ds, "Books");