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!

while loop to fill listbox, missing first record

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.

Why is my while loop skipping one row?

Thanks in advance,

Jason
 
Not sure if this'll work, but try replacing your While/End While with a Do/Loop While loop.

There's a thin line between genius, and insanity!
 
Thanks, TOAD. Someone else actually helped me with it: I had done a datareader.read() statement above the while loop in the code, and that caused the problem when reading for the while loop. Problem solved!

Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top