我定义了:
SqlDataReader myreader;
myreader=this.sqlSelectCommand1.ExecuteReader();
我想在datagrid中显示myreader的内容,于是我:
this.dataGrid1.DataSource=myreader;
但这里datagrid没有databind()属性,
我该怎样绑定?谢谢!

解决方案 »

  1.   

    this.dataGrid1.SetDataBinding(dataView1,null);
      

  2.   

    查一下this.dataGrid1.SetDataBinding(),
      

  3.   

    我试过了this.dataGrid1.SetDataBinding(),
    如果是this.dataGrid1.SetDataBinding(dataset,“”)就可以,
    但我这里是myreader。另外,有datasource,但没有databind啊
      

  4.   

    赋了DataSource就行啦,还要绑什么?
      

  5.   

    改为:SqlDataAdapter oda = new SqlDataAdapter(sql,connection);
    DataTable dt = new DataTable();
    oda.Fill(dt);
    this.dataGrid1.DataSource=dt;