Datareader Problem

  • Thread starter Thread starter Bernie Hunt
  • Start date Start date
B

Bernie Hunt

Sorry folks, I sure this is a stupid one, but I'm stuck. Just starting
with .Net so working with the ado.net objects are not natural to me yet.

This routine should open a datareader with a lot of records, step through
the records and display the field contents to text boxes on a form, along
with a running total displayed on the form. Nothing fancy.

The problem is it only displays one record. I verified the select
statement pushs are 1K records, so I have to assume a problem in my loop.

Can anyone tell me what stupid thing I'm doing wrong?

Thanks,
Bernie

Private Sub ProcessReport()
Dim drPatients As Odbc.OdbcDataReader
Dim intPatientCounter As Integer 'counter for processed
patients

intPatientCounter = 0

cxnEclipse.Open()
txbStatusOutput.Text = "Connection to Eclipse Open"
txbStatusOutput.Text = "Retrieving Patient List"
drPatients = cmdGetPatientList.ExecuteReader()
txbStatusOutput.Text = "Processing Patients"

Do While drPatients.Read
txbTotalPatients.Text = CStr(intPatientCounter + 1)
txbPatientName.Text = RTrim(CStr(drPatients("LastName"))) &
", " & RTrim(CStr(drPatients("FirstName")))
txbPatientID.Text = CStr(drPatients("PatientID"))
Loop
txbStatusOutput.Text = "Patients Completed"

drPatients.Close()
cxnEclipse.Close()
txbStatusOutput.Text = "Eclipse Connection Closed"

End Sub
 
Well, you are setting the text of the textboxes to the information contained
in the current record. So it loops through your data, and you end up seeing
the last record on the screen, because you keep replacing the data in the
textboxes each iteration. Additionally, you are never incrementing your
counter.

This is not an ADO issue. This is an issue with the flow of your program.
Did you expect the textboxes to contain 1000 records worth of data?
 
Marina,

Thanks for the quick replay.

I warned you it was going to be something stupid. I was trying to
increament the counter in the same statement as assigning it to the text
box, old bad habit from C.
Did you expect the textboxes to contain 1000 records worth of
data?

No, they should only contain the current/last set of data. I got confused
by the speed of the query. It's previous internation was in Crystal and
took much longer to process. I am pleasently supprised with the speed of
the .Net ODBC connection. Based on article written about it, I was
expecting the query to take much larger to process.

Thanks!
Bernie
 
Back
Top