Reputation: 31
I'm working on a GUI and when I'm pulling information from a SQL database, I'm having issues with the results. Instead of the information I've requested, I'm getting the following:
Here is the code i am using:
Upvotes: 1
Views: 101
Reputation: 29026
You need to assign the ValueMember
and DisplayMember
from the collection that you are using to bind the combobox. Here you are fetching only the name both the fields can be "name"
suppose you are taking some vehicle_id
and name
, probably "vehicle_id"
will be the ValueMember
. So use like this:
cbSelectVehicle.ValueMember="name";
cbSelectVehicle.DisplayMember="name";
cbSelectVehicle.DataSource=dt_vehicle;
DisplayMember
is nothing but what we seen in the UI, where as the valueMember is hidden but we can access them through code.
Upvotes: 1