private void Form1_Load(object sender, EventArgs e)
        {
            SqlConnection objcon = new SqlConnection("server=LENOVOT220;uid=sa;pwd=314;database=JxhSystem");            objcon.Open();            string sqltr = "select (case when xrate is not null then xrate else 0 end ) as xrate,cc=cast(case when stime is null then 0 when stime = 0 then 0 else sdtimep * 1.0/ stime*100 end as decimal(18,2)),(case when sdtimep is not null then sdtimep else 0 end) as sdtimep,cdepartname,invcode,ccuscode,csocode,qty,rqdate,mocode,prdatee,prqty,status,(case when ttime is not null then ttime else 0 end) as ttime,(case when stime is not null then stime else 0 end) as stime,prqty6,prqty7,prqty1,prqty2,prqty3,prqty4,prqty5,re from Jx_momorderp where(sdtime<=stime or sdtime<>stime or stime is null or sdtime is null) order by cdepartname,status desc";            SqlDataAdapter objpter = new SqlDataAdapter(sqltr, objcon);            DataSet objset = new DataSet();            objpter.Fill(objset, "ds");            dataGridView1.AutoGenerateColumns = true;            dataGridView1.DataSource = objset;            objcon.Close();              }
dataGridView1.DataSource = objset;
后面就是加不上dataGridView1.DatBind();上面的绑定代码该怎么写?谢谢大虾们

解决方案 »

  1.   

    winform下不用dataGridView1.DatBind(); 吧,指定数据源就行了
      

  2.   

      dataGridView1.DataSource = objset; 
    已经绑定了
      

  3.   

    数据我知道绑定了 为什么不显示数据?刚下winform代码
      

  4.   

    不用加 可以了 你用的是Windows窗体,Web窗体才要
      

  5.   


    DataTable dt = new DataTable();
    dt = objset.Tables[0];dataGirdView1.DataSource=dt;
      

  6.   

    判断下 objset.Tables["ds"].Rows.Count,看看有没有行,断点调试下!不是不用,是根本就没有这个方法!
      

  7.   

    刚才没看见,你绑定的怎么能是数据集呢?
    dataGirdView1.DataSource=objset.Tables["ds"];
      

  8.   

    如果要添加自己定义的模板列,就首先编辑和添加DataGridView的列,然后通过读取DataSet的内容填充到DataGridView中
    DataTable dt = objset.Tables[0];
    for (int i = 0; i < dt.Rows.Count; i++)
    {
       //用一个对象数组保存数据表dt各字段的内容
       object[] obj = new object[] {dt.Rows[i]["Field1"],
                                    dt.Rows[i]["Field2"],
                                    dt.Rows[i]["Field3"],
                                    ......
                                    dt.Rows[i]["FieldN"]};
      //循环添加所有的数据行 
      DataGridView.Rows.Add(obj);
    }
      

  9.   

    如果你的DataGridView的属性AutoGenerateColumns=true的话,应该可以显示
      

  10.   

    datagridview.Columns[0].PropertyName=objset.Tables[0].Columns[0].Name;
    datagridview.Columns[1].PropertyName=objset.Tables[0].Columns[1].Name;
    datagridview.Columns[2].PropertyName=objset.Tables[0].Columns[2].Name;分别对应下去就好,注意不能对应错了
      

  11.   

    vs2005中不用啊!你的sql语句有问题吧!下边的都没错!
      

  12.   

    dataGridView1.DataSource = objset.Tables[0].DefaultView;就行了