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();
    }
我这样绑定``居然出错``我找不到原因````帮帮忙```

解决方案 »

  1.   

    1、SqlConnection con = new SqlConnection(); 这一句,没有指定数据库连接的字符串。2、SqlDataAdapter sda = new SqlDataAdapter(); 没有指定数据库连接//修改如下
     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.   

    1. ASP.NET 2.0一般使用数据源控件进行绑定操作
    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();
        }