SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=Northwind;Integrated Security=True;Persist Security Info=True");
        SqlCommand cmd = new SqlCommand("select * from Employees",con);
        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand = cmd;
        con.Open();//打开数据库连接 
        DataSet ds = new DataSet();
        sda.Fill(ds, "Employees");//用Employees表填充数据集 
        con.Close();//关闭数据库连接 
        this.GridView1.DataSource = ds;
        this.GridView1.DataBind();
老说我编译出错,哪错了啊?谢谢

解决方案 »

  1.   

            SqlDataAdapter sda = new SqlDataAdapter("select * from Employees","Data Source=(local);Initial Catalog=Northwind;Integrated Security=True;Persist Security Info=True"); 
            DataSet ds = new DataSet(); 
            sda.Fill(ds, "Employees");//用Employees表填充数据集 
            this.GridView1.DataSource = ds; 
            this.GridView1.DataBind();就行了。
      

  2.   

    this.GridView1.DataSource = ds.Tables[0].DefaultView;不好意思。
      

  3.   

    补充一下,这句话的错误在sda.Fill(ds, "Employees");这句,没什么特别的错误提示,只说编译出错;
    但搞笑的是,我把Employees的双引号重新敲下,又能编译了