Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Displaying all rows in vb .net from sqll query

Posted on 2007-11-23
3
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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 143

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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

705 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