combobox data binding problem

venablc

Member
Joined
Jul 18, 2006
Messages
18
Programming Experience
Beginner
Hi,

Have been writing in VB .net for a few years now but this is the first time I have attempted to use data binding and I am having a problem which I just can't understand...

I am creating a dataset and populating it using a data adapter, it all seems to work fine up until this point, I then set the datasource for my combobox to the dataset but when I set the ValueMember i get the following error:

VB.NET:
Cannot bind to the new display member. Parameter name: newDisplayMember

what's even stranger is that although I set the displayMember property and there is no error the value is not actually set but although an error is thrown when setting the valueMember, the displayMember property actually takes on the value i have assigned to the valueMember property???

Here is my code:

VB.NET:
DAservices = New SqlClient.SqlDataAdapter(SQLservices, conn)

DSservices = New DataSet()

DAservices.Fill(DSservices)

CMBservice.DataSource = DSservices

CMBservice.DisplayMember = "description"

CMBservice.ValueMember = "serviceid"

CMBservice.Refresh()

This is extremley confusing and i hope someone will be able to point me in the right direction :)

Regards,

Chris V
 
Dataset is a collection of tables. You cannot have a combo use it as a datasource (because it doesnt know which table to pick) without setting the DataMember (if it has one). As an analogy, consider that it makes no sense to say "combo, use that database as your datasource, and the column name is BlahBlah" - you didnt specify which table the combo is to use, and databases dont have columns

Read this:
http://www.vbdotnetforums.com/ado-net/26286-dataset-datareader.html

Then the DNU link in my signature (for info)

Then read the DW2 link in my sig, section "Creating a Simple Data App" - that gets you started on data access the easy/proper way.. Don't start out writing binding code by hand; it's boring and not necessary
 

Latest posts

Back
Top