Using the DataTextField and DataValue Field in a ListBox

L

l7alabeh

Hi,

I am trying to take from a database 3 values, concatenate the first two
of them and insert them in a ListBox (in the DataTextField) and the 3rd
value in the DataValueField.

The problem is that I am able only to add the first two values
concatenated (using the DataReader) but the DataValueField is not
taking any new value, it is taking the value of the text.

Can you please help me to solve this problem?
 
E

Eliyahu Goldin

What do you think your car mechanic will answer you if you call him
complaying that the car has a problem?

Post your code.
 
L

l7alabeh

This is the code:

Sub ListBoxBind()

connstrconf.ConnectionString = strcnnconf

Dim NameDataReader As OleDbDataReader
Dim NameOleDbCommand As OleDbCommand


NameOleDbCommand = New OleDbCommand("select first_name,
last_name, dbid from cfg_person", connstrconf)

connstrconf.Open()
NameDataReader = NameOleDbCommand.ExecuteReader()


Do While (NameDataReader.Read())
ListBox1.Items.Add(NameDataReader.GetValue(0) & " " &
NameDataReader.GetValue(1))
ListBox1.datavaluefield = NameDataReader.GetValue(2)
Loop

NameDataReader.Close()
connstrconf.Close()
End Sub
 
E

Eliyahu Goldin

datavaluefield is supposed to be set to the name of the field. Your code
assigns to it the value of the field. And anyway, datavaluefield is used
only in databinding and you are not using any databinding, you are adding
items programatically.

You should do something like

ListBox1.Items.Add(New ListItem (NameDataReader.GetValue(0) & " " &
NameDataReader.GetValue(1), NameDataReader.GetValue(2)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top