Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

first row missing from listbox when using while loop and datareader 1

Status
Not open for further replies.

JGALEY

IS-IT--Management
May 21, 2003
105
US
I have a web app connecting to a SQL Server db. I use a stored procedure with a datareader to populate a listbox with a row for each record occurring on a certain date. I am using the following while loop for this:

While drGetPMs.Read
lbPMByDate.Items.Add(New ListItem(drGetPMs("EHKey") & " " & drGetPMs("PMType") & " " _
& drGetPMs("DatePM") & " " & drGetPMs("Status") & " " & drGetPMs("Meter"), _
drGetPMs("PMUID")))
End While

If there are 6 rows returned by the stored procedure, the listbox shows 5, leaving out the first record. When debugging, I can see the loop executing fully 5 times; however, on the 6th time the loop exits after the "while drGetPMs.Read" line.

The results do not show the first record from the result set of the stored procedure. Why is my while loop skipping the first row?

Any direction most appreciated!

Jason
 
Are you sure that you didn't read datareader once before while loop.
 
That did the trick: I had started it reading (like I normally would), and then I had it reading again in the while loop.

U R da man! Thanks!

Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top