Question binding data to a listbox and combobox

kfirba

Well-known member
Joined
Dec 29, 2012
Messages
77
Programming Experience
1-3
Hello!

I'm tring to bind data into my listbox and combobox ,this is what i've done so far:

        lstBooks.DataSource = borrowDS.Tables("Books")
        lstBooks.DisplayMember = "BookName"
        lstBooks.ValueMember = "BookID"

cboCostumers.DataSource = borrowDS.Tables("Costumers")
        cboCostumers.DisplayMember = "CostumerLastName " + "CostumerName"
        cboCostumers.ValueMember = "CostumerID"


when im running the application, I see no data in there :O

any idea why?

P.S.
I would like to ask about Queries.

How do i create a query that will update a column in a row?
I know the SQL syntax, I just don't know how to do it >.<
 
Last edited:
Firstly, while binding will work when you set the DataSource first, you should always set the DisplayMember and ValueMember first.

With regards to the DisplayMember, it must be the name of a column or property in the data source. Do you have a column in your Costumers table named ""CostumerLastName CostumerName"? I think that it's safe to say that you don't. You appear to be trying to display data from two columns, which is not possible. You would have to add a new column and set its Expression property to combine the data from the other two columns. You can then set the DisplayMember to the name of that new column.

As for updating a column in a row, that is a completely separate topic and does not belong in this thread. I'll answer it here this time but, in future, please keep each thread to a single topic and each topic to a single thread. Check out this thread of mine:

Retrieving and Saving Data in Databases

If you want to retrieve data from the database, edit it locally and then save it, look at the examples using a data adapter. If you just want to edit the data directly in the database, look at the example that uses ExecuteNonQuery.
 
Back
Top