473,379 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

VB.Net Datareader skips first record in results

rob
I'm having some trouble with this..

My VB datareader seems to skip the first record in the reader. I've
looked at my query in enterprise manager to confirm what I am suppose
to receive back, and what the data reader starts at is the second
record in the reader.

I've done read test to make sure there is a result in the datareader
("If rd.read Then blah") but does that advance the row position? Can
I set it back?

Here's some code from the application. It outputs to a listview
control.
Do While objRD.Read

lstName.Items.Add(objRD("CustID"))
lstName.Items(I).SubItems.Add(objRD("LastName"))
lstName.Items(I).SubItems.Add(objRD("FirstName"))
lstName.Items(I).SubItems.Add(objRD("Phone"))

I += 1

Loop

I've made sure my query is OK, I made sure the data reader was closed
and opened properly-- I dont know what else to check. I dont want to
use a data grid control if possible.

any thoughts here are appreciated-- thanks

Rob (id******@msn.com)
Jul 19 '05 #1
2 10097
Yes, the Read method moves you to the next record, but

"rob" <id******@msn.com> wrote in message
news:e7**************************@posting.google.c om...
I'm having some trouble with this..

My VB datareader seems to skip the first record in the reader. I've
looked at my query in enterprise manager to confirm what I am suppose
to receive back, and what the data reader starts at is the second
record in the reader.
No, the DataReader initializes itself PRIOR to the first record, so you need
to call Read BEFORE accessing any data.

See:
ms-help://MS.VSCC/MS.MSDNQTR.2002OCT.1033/cpref/html/frlrfsystemdataoledbole
dbdatareaderclassreadtopic.htm

I've done read test to make sure there is a result in the datareader
("If rd.read Then blah") but does that advance the row position? Can
I set it back?
A DataReader is the only ADO.NET object that provides connected access to
your data, it's read only and FORWARD only -- no going back unless you
re-initialize the DR.


Here's some code from the application. It outputs to a listview
control.
Do While objRD.Read

lstName.Items.Add(objRD("CustID"))
lstName.Items(I).SubItems.Add(objRD("LastName"))
lstName.Items(I).SubItems.Add(objRD("FirstName"))
lstName.Items(I).SubItems.Add(objRD("Phone"))

I += 1

Loop

Are you sure your variable (I) is initialized at zero prior to this loop
since all collections are zero-based?
Have you considered binding the listbox to the DataReader instead of
populating it manually?
I've made sure my query is OK, I made sure the data reader was closed
and opened properly-- I dont know what else to check. I dont want to
use a data grid control if possible.

any thoughts here are appreciated-- thanks

Rob (id******@msn.com)

Jul 19 '05 #2
rob
Scott- thanks for your help. My "I" wasnt initialized to zero AND I
had an extra read test in there. That fixed it up.

I didnt use data binding b/c I like to see what's in the code-- I dont
know-- I'm still new to VB.net, maybe I'll change my mind in a while.

Thanks for the help though!

Rob
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: lakshmi | last post by:
Hi all I'm trying to traverse through the results from a query that returns more than 1 row. The data reader reads only the first row. The following code doesn't work. Let me know what's wrong....
1
by: Rob via .NET 247 | last post by:
Ok, I'm new to .NET so I'm afraid I'm doing something stupidhere, but I'm trying to populate a DataSet manually from aDataReader, and its turning out to be ridiculously difficult. Yes, I could use...
8
by: KathyB | last post by:
Please tell me where I'm going wrong on the marked lines***. The code is fine to that point. I've only used this code to populate dropdownlists using databind to the control. Here, I just need to...
14
by: Jacko | last post by:
Hi guys, Say I made a SELECT statement to my sql DB that would return 50 rows that I will use a sqldatareader to access. Instead of iterating through each and every row of the datareader, I'd...
2
by: David Beaven | last post by:
I am creating an aspx page to show (i.e. read only) hundreds or probably thousands of items from two database queries. The user may of course only want to read one or two pages worth. I have (I...
2
by: rob | last post by:
I'm having some trouble with this.. My VB datareader seems to skip the first record in the reader. I've looked at my query in enterprise manager to confirm what I am suppose to receive back,...
10
by: jimmy | last post by:
Hi again, sorry for posting two questions so close together but im working on a school project which is due in soon and running into some difficulties implementing the database parts. I have the...
3
by: Osamede.Zhang | last post by:
I have some code like this: SqlCommand cmd = new SqlCommand("get_storeid_byuser", cn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@username", SqlDbType.VarChar, 50).Value...
2
by: Chris | last post by:
>From just about everything I have read, a DataReader reads only one record at a time from a database and only caches that one record in the client's memmory. However, a colleague of mine noted...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.