GridView是不是集合了2003的DataGrid和DataView
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GirdVDtaBind();
}
}
protected void GirdVDtaBind()
{
SqlConnection con = new SqlConnection();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from jobs");
DataSet dt = new DataSet();
sda.Fill(dt,"emp");//提示这行出错
this.GridView1.DataSource=dt.Tables["emp"];
this.GridView1.DataBind();
}
我这样绑定``居然出错``我找不到原因````帮帮忙```
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.GirdVDtaBind();
}
}
protected void GirdVDtaBind()
{
SqlConnection con = new SqlConnection();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = new SqlCommand("select * from jobs");
DataSet dt = new DataSet();
sda.Fill(dt,"emp");//提示这行出错
this.GridView1.DataSource=dt.Tables["emp"];
this.GridView1.DataBind();
}
我这样绑定``居然出错``我找不到原因````帮帮忙```
protected void GirdVDtaBind()
{
using(SqlConnection con = new SqlConnection("数据库连接字符串"))
{
SqlDataAdapter sda = new SqlDataAdapter("select * from jobs",con);
DataSet dt = new DataSet();
sda.Fill(dt,"emp");//提示这行出错
this.GridView1.DataSource=dt.Tables["emp"];
this.GridView1.DataBind();
}
}
2.
protected void GirdVDtaBind()
{
SqlConnection con = new SqlConnection("你的连接字符串");
SqlDataAdapter sda = new SqlDataAdapter("select * from jobs", con);//你的查询语句
DataSet dt = new DataSet();
con.Open();
sda.Fill(dt,"emp");//提示这行出错
con.Close();
this.GridView1.DataSource=dt.Tables["emp"];
this.GridView1.DataBind();
}