private void Page_Load(object sender, System.EventArgs e)
{
//第一种方法(用DataAdapter)
//SqlConnection conn=new SqlConnection("server=(local);uid=sa;pwd=;database=ceshi;");
//SqlDataAdapter rs=new SqlDataAdapter("select * from ceshi",conn);
//DataSet ds=new DataSet();
//rs.Fill(ds,"表一");
//DataGrid1.DataSource=ds.Tables["表一"].DefaultView;
//DataGrid1.DataBind();
//第二种方法(用Command和DataReader)
SqlConnection conn=new SqlConnection("server=(local);uid=sa;pwd=;database=ceshi;");
SqlCommand myCommand = new SqlCommand("select * from ceshi", conn);
conn.Open();
SqlDataReader dr = myCommand.ExecuteReader();
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
conn.Close();
// 在此处放置用户代码以初始化页面
}