472,119 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 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 9968
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Rob via .NET 247 | last post: by
2 posts views Thread by David Beaven | last post: by
3 posts views Thread by Osamede.Zhang | last post: by
reply views Thread by leo001 | last post: by

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.