首页 > 学院 > 开发设计 > 正文

DataReader 绑定DataGridView有两种方式

2019-11-17 03:08:58
字体:
来源:转载
供稿:网友

DataReader 绑定DataGridView有两种方式

第一种:借助于BindingSourcesqlDataReader Sdr=通过查询函数得到的sqlDataReader类型的数据;BindingSource Bs=new BindingSource() ;Bs.DataSource=Sdr;DataGridView.DataSource=Bs;

第二种:借助DataTablesqlDataReader Sdr=通过查询函数得到的sqlDataReader类型的数据;DataTable Dt=new DataTable();Dt.Load(Sdr);DataGridView.DataSource=Bs;

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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表