combobox and db?

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
on my frmAddTests, i have a combobox "category" which displays the name of category (the displayMember is "category name", the valueMember is "category ID". I have this line of code to add a value into a column "categoryID" to the table "tests" when adding a new test.
VB.NET:
              SqlCommandAddTest.Parameters(3).Value = ComboBoxCategory.ValueMember
When add a test, the app should look for the categoryID that corresponds to the category name selected in the combobox, but at runtime it throws this error: "Input string was not a correct format". Is there anything wrong with my code? or maybe it's caused by something else? plz help
 
I figured out that ComboBoxCategory.ValueMember only gives the ValueMember name but but not actual value, I got around this by having another command contains SQL retrieving the CategoryID from category table where the parameter is category name which is selected from the combobox. There must be an easy way to retrieve the valuemember directly frm the combobox, am i right?
 
Back
Top