Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:04:38+00:00 2026-06-10T14:04:38+00:00

I am going to do my best to explain this, though admittedly I have

  • 0

I am going to do my best to explain this, though admittedly I have not attempted much in months so I’m not only rusty, I wasn’t good to being with.

I am using visual web developers and asp, vb is the code behind with a sql db.

If I select a columns from a table, for example:

sqlCmd.CommandText = "SELECT Username, W1, W2, W3, W4 FROM tablename"

Say there are multiple rows in this table with data in these columns.

When I do a datareader, or how I have been shown, I declare dr like:

Dim dr As Data.SqlClient.SqlDataReader

I can work with the selected items such as:

dr.item(0)
dr.item(1)

etc.

But the only items I can work with are the first row of items selected. How do I select all of the rows in the table. Or how can I work with the data from multiple rows using dr.item or by somehow telling it to move onto the next row so that dr.item(0) becomes the username for the second row in the table.

I hope that made sense and I’m sorry if this is a stupid question. I appreciate the time and help in advance. Thanks guys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:04:39+00:00Added an answer on June 10, 2026 at 2:04 pm

    SqlDataReader.Read advances the reader to the next record and returns true when there is at least one other row:

    Using conn = New SqlClient.SqlConnection(connString)
        Using cmd = New SqlClient.SqlCommand("SELECT Username, W1, W2, W3, W4 FROM tablename", conn)
            conn.Open()
            Using dr = cmd.ExecuteReader()
                While dr.Read()
                    Dim UserName As String = dr.GetString(0)
                    ' ... '
                End While
            End Using
        End Using        
    End Using
    

    Use Using to dispose anything that implements IDisposable as soon as possible. It will also close connections implicitely.

    Edit: using a DataTable

    How do I select all of the rows in the table

    The DataReader approach above works well, but if you want to select all rows anyway and it’s ok to load all into memory, you can use a DataTable instead. Then you could also access each row via indexer like an array or list:

    Dim tblUsers = New DataTable()
    Using conn = New SqlClient.SqlConnection(connString)
        Using da = New SqlClient.SqlDataAdapter("SELECT Username, W1, W2, W3, W4 FROM tablename", conn)
            da.Fill(tblUsers)
        End Using
    End Using
    ' access a row via index: '
    Dim row10 As DataRow = tblUsers.Rows(9)
    Dim user10 = row10.Field(Of String)("Username")
    ' of course you can also iterate all rows: '
    For Each row As DataRow In tblUsers.Rows
        Dim userName = row.Field(Of String)("Username")
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I'm going to try my best to explain my problem. I have this
I'm going to try and explain this the best I can... I have one
Alright, I'm going to try to explain this as best as possible: I have
I'm going to try to explain this best I can I will provide more
I am not sure if I am going about this the best way, but
Sorry in advance im going to try and explain this as best as possible....
I'm going to try and explain this the best I can. I used this
This is going to be hard to explain but I'll try my best. I
This will be a bit hard to explain but I am going to have
I am going to try and explain this as best as I can, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.