Combobox binding?

  • Thread starter Thread starter al
  • Start date Start date
A

al

Greetings,

In VB6,there was the combobox controls. It had a property called
datalist where you can bind a column in the recordset to it. This
property would be used to have changes made to the text in the
combobox be reflected on the recordset, as a way of databinding. Now,
in ADO.NET, there is the ValueMember property, but the problem is it
can't be used with datareader. Is there any other property equvalent
to valuemember and can be used with datareader???


MTIA,
Grawsha
 
Hi al,

No, datareader is not meant to act like a datasource (except for asp.net).
Rather, use it to fill a datatable and bind the datatable to combobox.
 
al, old school ado kept a connection to the db, so you could bind no
problem. A datareader is roughly analagous to the way a recordset worked in
that it can only be used with an active connection to the database. When
first coming over to ADO.NET, remember that it's not the next version of
ADO, it's a new paradigm and while you still have a connection and command,
that's about the only similarity. Like Miha suggested, you can either walk
through the datareader and load your control:


while(dr.Read()){
combBox1.Items.Add(dr.GetString(0));
}

or create a datatable and bind to it setting the datasource, displaymember
and valuemember (Display Member is what is shown in the box, ie William
Ryan, but if I had an Employee number in the same row in my table, and you
set the ValueMember to EmployeeID, then the SelectedValue would be 244 for
example, while the selectedItem would be William Ryan.

HTH,

Bill
 
Miha Markic said:
Hi al,

No, datareader is not meant to act like a datasource (except for asp.net).
Rather, use it to fill a datatable and bind the datatable to combobox.

So this would require a dataset, correct?
 
Back
Top