private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=数据库;Integrated Security=True"))
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {                    cmd.CommandText = @"select * from T_GongsiXinxi";
                    //conn.Open();
                    DataSet DS = new DataSet();
                    SqlDataAdapter DA = new SqlDataAdapter(cmd);
                    DA.Fill(DS);
                    this.dataGridView1.DataSource = DS.Tables[0];
                    conn.Close();
                }

解决方案 »

  1.   

     DS.Tables[0];
    表中有数据吗?
    怀懝是个空表.
      

  2.   

     this.dataGridView1.DataSource = DS.Tables[0];
     this.dataGridView1.DataBind();
                        conn.Close();
      

  3.   


    确实是这个事件问题,先用一个Button测试下吧
    ------------------------------------------------
    //是CellContentClick 事件的问题
    //你这个代码根本没执行 知道吗?
    //CellContentClick 事件,必须单元格里有内容(文字) 点击了才出发
    //不知道你为什么要用这个事件? 换个Button先试一下吧
      

  4.   

    CellContentClick-------这个事件的作用是,点击单元格里面的内容才能触发---就是点击了单元格里的字才能触发
      

  5.   

    DA.Fill(DS,"table"); //给个表名,整个的意思就是你把数据填充到数据集的table表中,取的是下标[0]去的就是table的数据了(我们老师这样给我们教的...)
      

  6.   

     DA.Fill(DS);
    这里设置一个断点,看看能进去不,还有DS有值没有
      

  7.   

    在Form_Load中
    using (SqlConnection conn = new SqlConnection(@""))
                {
                    conn.Open();
                    using (SqlCommand cmd = conn.CreateCommand("select * from T_GongsiXinxi",conn))
                    {
                        DataSet DS = new DataSet();
                        SqlDataAdapter DA = new SqlDataAdapter(cmd);
                        DA.Fill(DS);
                        this.dataGridView1.DataSource = DS.Tables[0];
                        conn.Close();
                    }
    }
      

  8.   

    干么要写在这事件况且也不对,写Load,button_click,或者你可以试试类型化的
      

  9.   

    这行代码忘记了!this.dataGridView1.DataBind();