Bind ListBox

A

Andre

Hi,

I try to bind my dataset to a listbox, but i can't find a way to make it
work. I'm lost ;o)

Dim ConnStr As String = "myconnectionstring..."
Dim SQL As String = "SELECT Town from Info group by Town;"
Dim myConnection As New SqlConnection(ConnStr)
Dim myCommand As New SqlCommand(SQL, myConnection)
Dim MyAdapter As New SqlDataAdapter
Dim mydataset As New DataSet

MyAdapter.SelectCommand = myCommand
myConnection.Open()
MyAdapter.Fill(mydataset) --------- or MyAdapter.Fill(mydataset, "Town")

--- this line is for a test, don't know if i need to use it -------
Dim LbView As New DataView(mydataset.Tables("Town"))

LB1.DataSource = mydataset
LB1.DataBind()
myConnection.Close()

On the LB1.Datasource line :
if i use "= mydataset" i receive only system.data.datarowview for all the
item in my listbox.
if i use "= mydataset.LbView .. same thing
if i use "= mydataset.container ... my listbox is empty, or fill with empty
string

Did someone have any idea what is wrong with my code ?

Thank you
 
K

Ken Tucker [MVP]

Hi,

LB1.DataSource = Lbview or LB1.Datasource = mydataset.tables("Town")
LB1.Displaymember = "Town"

Ken
 

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

Top