点击按钮从数据库返回一个数据集,并将其重新绑定到dataGridView1显示!我用的方法是:
            dataGridView1.ClearSelection();
            dataGridView1.DataSource = ds;
            dataGridView1.DataMember = "HD";
            ds.AcceptChanges();
但是不能够显示!求大家给个意见!谢谢!急需!!!!!!            

解决方案 »

  1.   

     DataSet ds = new DataSet(); 
                ds = //你得到的数据集; 
                dataGridView1.DataSource = ds.Tables[0].DefaultView;
      

  2.   

    不行啊,实现不了还是不能显示!并且我有加了一句
    dataGridView1.DataMember = ds.Tables[0].TableName;还是不能显示的!在帮忙想想!谢啦!这个是我的btn事件!biz.updataHDInf(date1 ,date2);是BLL层的一个方法,返回一个数据集包含一个表表明为HD,请求高手指教!private void button2_Click(object sender, EventArgs e)
            {            string date1 = dateTimePicker1.Text;
                string date2 = dateTimePicker2.Text;
                DataSet ds = biz.updataHDInf(date1 ,date2);
                if (ds == null)
                { MessageBox.Show("筛选失败,请重新核对您的日期!"); }
                else
                {
                    dataGridView1.ClearSelection();
                    dataGridView1.DataSource = ds;
                    dataGridView1.DataMember = ds.Tables[0].TableName;
                }
             }
      

  3.   

    楼主你忘了databind();
    //dataGridView1.DataBind();
      

  4.   

    if (ds == null) 
                { MessageBox.Show("筛选失败,请重新核对您的日期!"); } 
                else 
                { 
                    dataGridView1.ClearSelection(); 
                    dataGridView1.DataSource = ds; 
                    dataGridView1.DataMember = ds.Tables[0].TableName; 
                } 
    -----改为:if (ds == null) 
                { MessageBox.Show("筛选失败,请重新核对您的日期!"); } 
                else 
                { 
                    dataGridView1.DataSource = ds.Tables[0]; 
                    //dataGridView1.DataMember = ds.Tables[0].TableName; 
                } 
      

  5.   

    不行啊,实现不了还是不能显示!并且我有加了一句 
    dataGridView1.DataMember = ds.Tables[0].TableName;还是不能显示的!在帮忙想想!谢啦! --------------
    是什么都没显示,还是只显示了字段名?
    如果只显示了字段名,那就是没有数据。
    如果什么都没显示,跟踪看看SQL语句有没问题
      

  6.   

    dataGridView1.DataSource = ds; 
    只 要这一行就可以了