Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get the Database ID of a value populated in Combo box
Posted
Comments
Jαved 27-Jun-12 7:44am    
Please explain clearly what you want.

1 solution

Issue a Select command on the database:
SQL
SELECT Id FROM MyTable WHERE NameOfValueColumn = value

Alternatively, create a class which contains the ID and the value you to display (among others) and override the ToString method. Make the overridden method return the string you want to display, and pass the ComboBox an array of instances. It will display the string, and you can get the original object instance from the SeletedItem property without further database access:

C#
MyClass mc = MyComboBox.SelectedItem as MyClass;
Console.WriteLine(mc.Id);
 
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