Click here to Skip to main content
16,014,392 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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


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


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

Regards

H.Maadani
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900