DataReader 绑定DataGridView有两种方式<

第一种:

借助于BindingSource  sqlDataReader Sdr=通过查询函数得到的sqlDataReader类型的数据;

BindingSource Bs=new BindingSource() ;

 Bs.DataSource=Sdr;

 DataGridView.DataSource=Bs;

第二种:

借助DataTable  sqlDataReader Sdr=通过查询函数得到的sqlDataReader类型的数据;

DataTable Dt=new DataTable();

Dt.Load(Sdr);

 DataGridView.DataSource=Bs;

获取DataGridView的选择的行  例如将选择的行的第一列的值转换成string的类型并赋给Num  string Num=Convert.ToString(DataGridView[0,DataGridView.CurrentCell.RowIndex].Value); 这样选中的行的第一列就转换成了string类型的数据,可以通过SQL语句进行其他的操作。

 

posted @ 2015-05-21 21:27  万物皆对象  阅读(194)  评论(0)    收藏  举报