Return data to listbox

B

backwards15

Simple question for you all. I'm new to ADO.net and i'm trying to run
a querry on a SQL 2000 database and return all the rows found to a
listbox.

Below the code i have returns one item to the listbox and if i run my
querry it otherwise should add another 3 items.

Is there anyway i can make a quick change to the code below in order
to do this.

Regards,

Andy

sql.Open()
Dim ds As New DataSet()
Dim da As New SqlClient.SqlDataAdapter(cmd)
da.Fill(ds, "Output")
If ds.Tables(0).Rows(0).Item(0) Is DBNull.Value Then
MessageBox.Show("no user found")
Else

Me.ListBox1.Items.Add(ds.Tables(0).Rows(0).Item(0).ToString + ", " +
ds.Tables(0).Rows(0).Item(1).ToString)
End If
sql.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, Application.ProductName,
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
 
W

William \(Bill\) Vaughn

Try a
For Each dr as DataRow in Table(0).Rows
' add to list box from dr
Next

There are lots of examples of manual and formal binding in my book.
hth
--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 

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