DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 09 Jul 2007 11:47:20 -0700,    posted on: microsoft.public.dotnet.framework.adonet        back       

Thread Index
  1    unknown
          2    William \(Bill\) Vaughn
          3    unknown


Return data to listbox   
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
Date:Mon, 09 Jul 2007 11:47:20 -0700   Author:  

Re: Return data to listbox   
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)
-----------------------------------------------------------------------------------------------------------------------

 wrote in message 
news:1184006840.040829.23640@e16g2000pri.googlegroups.com...

> 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
> 
Date:Mon, 9 Jul 2007 11:55:57 -0700   Author:  

Re: Return data to listbox   
Thanks, That helps
Date:Mon, 09 Jul 2007 12:28:45 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us