将combobox与datatable列绑定 [英] bind combobox with datatable column

查看:67
本文介绍了将combobox与datatable列绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

plz提供ma代码将Combobox与数据库的数据库列绑定到基于Window的项目(不是基于web的)。



我的代码是这样的...... < br $> b $ b

字符串QrySuppType =按类型asc从供应商类型中选择*;

MySqlCommand cmdQrySuppType = new MySqlCommand(QrySuppType,ConStr);

DataTable dtQrySuppType = cmdQrySuppType.ExecuteReader();

ddlSuppType.DataSource = dtQrySuppType;

ddlSuppType。

plz provide m a code to bind Combobox with datatable column of database for Window based project(not web based).

my code is like this...

string QrySuppType = "Select * from supplier_type order by type asc";
MySqlCommand cmdQrySuppType = new MySqlCommand(QrySuppType,ConStr);
DataTable dtQrySuppType = cmdQrySuppType.ExecuteReader();
ddlSuppType.DataSource = dtQrySuppType;
ddlSuppType.

推荐答案

让ddlSuppType是你的组合框,somekey是你的代码列,somedescription是你要显示的描述列,你可以从loat事件或你想要的任何其他地方调用这段代码。

Let ddlSuppType is your combo box and somekey is your code column, somedescription is description column you want to display, you can call this code in from loat event or any other place you want.
string QrySuppType = "Select * from supplier_type order by type asc";
MySqlCommand cmdQrySuppType = new MySqlCommand(QrySuppType,ConStr);
DataTable dtQrySuppType = cmdQrySuppType.ExecuteReader();
ddlSuppType.DataSource = dtQrySuppType;
ddlSuppType.DisplayMember = "somedescription"; 
ddlSuppType.ValueMember= "somekey" ; 



,希望这会对你有帮助。


that it, hope this will help you.


这篇关于将combobox与datatable列绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆