The .Read() moves to the next record, so you can just do something like this:
While thisReader.Read()
'Do something with value
MsgBox(thisReader(0).ToStr
End While
Main Topics
Browse All TopicsRight now I have a table called Products with 4 columns, one of which is simply called ProductName. Using the attached code, I can read the first cell which contains "Clamp" and it successfully displays inside my text box. But how do I tell VB to simply read the next cell down?
I thought it would be as simple as using TextBox1.Text = thisReader(1) but it gives me the error "Index was outside the bounds of the array."
I'm still learning VB so give it to me simple :)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Jaime makes a good point. The HasRows property is good to use before reading from SqlDataReader, but as you can see moving to next record is achieved by looping through thisReader.Read().
http://msdn.microsoft.com/
I appreciate your guys' help and I've managed to have each cell loop and provide me the information, but maybe I didn't explain what I'm trying to do.
I don't want to use a loop for the program to start from the beginning cell and eventually loop through every value until I reach the last cell in that column. I want the value from what ever cell i want when i want it.
If i want the value from the 6th cell in the column, i want to call that cell, not loop through each one.
Thank you
I would get your data back in a DataTable then and not a DataReader. Then you can access whichever row/column combination you want. If you want to maintain code that gets the data into DataReader, you can just use the DataReader to create DataSet or DataTable and then use that to display the exact data you want.
Here is an example: http://blogs.vbcity.com/dr
The underlying concept is you use DataAdapter's to fill DataTables from DataReaders.
Hope that helps.
Regards,
Kevin
I'm confused just reading that website you gave me, i'm so new to VB and what certain objects mean and do but i'm sure it contains the answer i'm looking for, I just don't know where to start lol. I'm going to post my entire code to show you what i have.
All I want the program to do (simply) without another 10 lines of useless code is to simply read the second cell of the ProductName column, or the third, or the fourth.
For example, if 0 inside the Reader is equal to the first cell, why cant i simply use 1 or 2 or 3. This is whats driving me up the wall, I don't understand why it can't be as simple as that.
Thank you for your patience.
Business Accounts
Answer for Membership
by: jaime_olivaresPosted on 2008-10-04 at 15:58:46ID: 22642546
use something like this:
If thisReader.HasRows Then ' important, check if there are rows first, to avoid exception
While thisReader.Read()
' do something with the row
End While
End If