DataReader 绑定DataGridView有两种方式

2018-11-14  本文已影响0人  PorcheWang

发布时间:2018-03-01 来源:网络 上传者:用户

第一种:借助于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语句进行其他的操作。

上一篇 下一篇

猜你喜欢

热点阅读