Solved

Displaying all rows in vb .net from sqll query

Posted on 2007-11-23
3
233 Views
Last Modified: 2013-11-26
I have a aspx pages that will restore a database when all the fields are populate by the Admin user. The first thing it does is check to see if there's any open connections. If there is let the admin user know by displaying all loginname via a label text box. However, I'm only able to get it to display the first row and only the first row. I wrote a store procedure that will query the master table in the database the Admin user is attempting to restore. What can I do this display all loginames? Any help is appreciated. Thanks

Here is the code that I'm using:


Private Sub CheckLiveConnections()

        Try

            'Define database connection

            myconnection = New SqlClient.SqlConnection("server=" & DropDownList1.SelectedItem.Value & ";user=xxxx; password=xxxx;database = ADMIN")
 

            myconnection.Open()
 

            Dim OpenConnections As New SqlClient.SqlCommand("EXEC GetConnections '" & DropDownList2.SelectedValue & "'", myconnection)
 

            'Call the sproc...

            Dim reader As SqlClient.SqlDataReader = OpenConnections.ExecuteReader()
 

            If reader.Read() Then

                Label9.Text = reader.Item(0)

            End If
 

        Catch ex As System.Exception

            Label9.Text = ex.Message

        End Try
 

    End Sub

Open in new window

0
Comment
Question by:redouard
  • 2
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 20340896
>What can I do this display all loginames?
you need 2 things:
* an idea about how you want to display it (GUI)
* use a while reader.Read() instead of a if reader.Read() to loop through the records...
0
 
LVL 2

Expert Comment

by:yossi_intlock
ID: 20341373
as angel said - this will do the job..
Private Sub CheckLiveConnections()

        Try

            'Define database connection

            myconnection = New SqlClient.SqlConnection("server=" & DropDownList1.SelectedItem.Value & ";user=xxxx; password=xxxx;database = ADMIN")
 

            myconnection.Open()
 

            Dim OpenConnections As New SqlClient.SqlCommand("EXEC GetConnections '" & DropDownList2.SelectedValue & "'", myconnection)
 

            'Call the sproc...

            Dim reader As SqlClient.SqlDataReader = OpenConnections.ExecuteReader()
 

            While reader.Read()

                Label9.Text += reader.Item(0) + "<BR/>"

            End While
 

        Catch ex As System.Exception

            Label9.Text = ex.Message

        End Try
 

    End Sub

Open in new window

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 20341945
after reflection... you might want to use a listbox instead of a textbox, and show each item in a dedicated row of output... depends how you want to display the data...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now