private void Form5_Load(object sender, EventArgs e)
        {
            string txt1 = "Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|fz.mdf;";
            txt1 += "Integrated Security=True;Connect Timeout=30;User Instance=True";
            string s = "select * from 客户";
            SqlConnection conn = new SqlConnection(txt1);
            SqlCommand cm = new SqlCommand(s, conn);
            SqlDataAdapter da = new SqlDataAdapter(cm);
            DataSet ds = new DataSet();
            conn.Open();
            int numberOfRows = da.Fill(ds, "客户");
            conn.Close();            this.dataGridView1.DataSource = ds.Tables["客户"];
        }

解决方案 »

  1.   

    dataGridView1.DataSource = ds.Tables["客户"];
    dataGridView1.Databind();
      

  2.   


    dataGridView1.DataSource = ds.Tables["客户"];
    //你只是指定了DGV的数据源,
    dataGridView1.Databind();
    //用这句代码进行绑定.
      

  3.   

    C/S不需要dataGridView1.Databind();
    断点打到
    this.dataGridView1.DataSource = ds.Tables["客户"];
    CTRL+ALT+I调出即时窗口
    执行ds.Tables["客户"].Rows.Count看有值不
      

  4.   

    是不是 WINFORM、??哥们你数据库里面有值没?
      

  5.   

    试试
    this.dataGridView1.DataSource = ds.Tables[0];
      

  6.   


    +1 检查一下Column配置
      

  7.   

    但是winForm里面 ,就算不用DataBind()也能显示出数据的,楼上的几位可以试试
      

  8.   

    你都用了适配器去填充ds 还用conn.Open() 和 conn。Close();干嘛呢? 试试下面的代码吧!  private void Form5_Load(object sender, EventArgs e)
      {
          string txt1 = "server=.;database=数据库名;uid=用户名;pwd=密码;"; 
          string s = "select * from 客户";
          DataSet ds = new DataSet();
          SqlConnection conn = new SqlConnection(txt1); 
          SqlDataAdapter da = new SqlDataAdapter(s,conn);
          da.Fill(ds,"kefu"); 
          this.dataGridView1.DataSource = ds.Tables["kefu"];
          this.dataGridView1.DataBind(); 
     }
      

  9.   

    this.dataGridView1.DataSource = ds.Tables[0];