Question Database / ListBox Query

dfenton21

Member
Joined
Apr 26, 2011
Messages
20
Programming Experience
Beginner
Hi All,

I've been learning VB.NET for a few months, and I'd appreciate if someone could assist me with this query.

For illustration purposes, lets assume I have a database table with three fields - EmpID(Key), EmpName and EmpSales. I can populate a ListBox with the EmpName field. However, if the user selects an item in the ListBox, I want to get the corresponding entry in the EmpSales field and display it in a textbox.

I know how to do this if the ListBox was populated with the EmpID field because it is the key, but not otherwise. Also, the EmpName field could and does contain duplicates but are actually different records, i.e. two people with the same name.

Can someone please assist me with this.

Thanks,
Damien.
 
Hi,

Thanks for your reply. I want to query the database each time the user makes a selection, i.e. the database would contain:
EmpID EmpName EmpSales
1 John Smith 100
2 Mary Brown 200
3 Mike Black 300

The ListBox contains the three names. When John Smith is selected, textbox.text = 100 and so on...

Thanks,
Damien.
 
You still need the ID. You just don't display it. Query the database to get the ID and the name. Bind the data to the ListBox, setting the DisplayMember and the ValueMember. When the user selects a name from the list, you get the corresponding ID from the SelectedValue property of the ListBox.
 
Back
Top