By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,442 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

Bind ListBox

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

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

Ken
----------------
"Andre" <lo*****@cablevision.qc.ca> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.