组合框显示数据库中的数据 [英] combobox display data from database

查看:62
本文介绍了组合框显示数据库中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框.我希望它显示数据库中的data/2列(我使用phpmyadmin).

我使用vb语言.在Visual Studio 2012/2015 Express中.

任何人都可以帮助我解决这个问题吗?

对不起,我的机器损坏了.

解决方案

要将.net中的ComboBox绑定到数据源,您需要设置3个属性:.DataSource,.ValueMember,.DisplayMember.

ValueMember用于选择(隐藏)的项目的值.

DisplayMember用于在项目列表中显示文本.

如果您希望将2列显示为DisplayMember,请通过查询将这两列连接为一列,然后将合并的列设置为DisplayMember.

如果我们谈论的是T-SQL:

从表中选择ID,Col1 +''+ Col2作为值

下面有一个有关如何使用Vb.net绑定组合框的示例:

http://vb.net-informations.com/dataset/bind- combobox.htm


i have a combobox . i want it to display data/2 columns from database(i use phpmyadmin) .

i use vb language. in visual studio 2012/2015 express.

anyone can help me resolve this problem ?

sorry for my broken eng.

解决方案

To bind a ComboBox in .net to a DataSource, you need to set 3 properties: .DataSource, .ValueMember, .DisplayMember. 

ValueMember is for the value of the item selected (hidden).

DisplayMember is for the Text to be displayed in the items list.

If you want to show 2 columns as DisplayMember, concatenate those two columns into one via you query and set that combined column as DisplayMember.

If we talking about T-SQL:

Select ID, Col1 + ' ' + Col2 as Value from Table

There is an example in the below on how to bind a combobox using Vb.net:

http://vb.net-informations.com/dataset/bind-combobox.htm


这篇关于组合框显示数据库中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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