Displaying all rows in vb .net from sqll query

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

redouardAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
>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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yossi_intlockCommented:
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
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.