向组合框添加值成员 [英] Adding value member to the combobox

查看:83
本文介绍了向组合框添加值成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我允许用户从组合框中选择用户全名,并从名称和姓氏列的user_details表中加载具有用户全名的组合框,现在我希望我的用户执行当用户被选中时,一项特定的任务,因此我试图为每个项目添加一个值成员,这将是user_details表中相应名称的雇员ID,因此我修改了查询以返回全名和empID,现在我需要知道将帮助我将empID添加为值成员的代码,即display成员将是全名,而对应的value成员将是empID,请检查代码.谢谢.

In my application i am allowing user to select the user full name from the combobox, i m loading the combobox with user full name from user_details table from first and last name column with a space in between, now i want my user to perform a certain task when the user is selected , hence i am trying to add a value member for every item, and that would be the employee id of the corresponding name from the user_details table, hence i modified the query to return the full name and the empID, now i need to know the code that will help me to add the empID as the value member, i.e display member would be the full name and the corresponding value member would be the empID, please check the code. Thanks.

Using cn As New SqlClient.SqlConnection(sqlConnStr)
                cn.Open()
                Using cmd As New SqlCommand(strSQLOwner, cn)
                    Using pdrOwnr As SqlDataReader = cmd.ExecuteReader
                        While pdrOwnr.Read
                  cboOwner.Items.Add(pdrOwnr.Item(0)) '' full name''
                 cboOwner.ValueMember = pdrOwnr.Item(1)''empID ''
                        End While
                    End Using
                End Using
            End Using

推荐答案

好吧,这不是一个好方法.我的建议是使用数据集.

我对VB语法不是很熟悉,所以要避免语法错误:

well, that is not a good way to do that. my suggesstion would be using a dataset.

I''m not very familiar with VB syntax, so spare the syntax errors :

Using datasource As new DataSet()
Using adapter As new SqlDataAdapter(cmd)
   adapter.Fill(datasource)
End Using
cboOwner.DataSource = datasource.Tables[0]
cboOwner.DisplayMember = "full name"
cboOwner.ValueMember = "empID"
End Using



这样,您将不需要一会儿,您就可以实现自己的目标.


---------------------

问候

H.Maadani



This way, you wont need a while, and you will reach your goal.


---------------------

Regards

H.Maadani


这篇关于向组合框添加值成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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