Hi,
In my record set, it's returning 67 rows. Some times(on iteration), am getting correct values from the record set and some times am getting wrong values from the record set. Am unable to solve this issue ? please help me out.

Dani AI

Generated

A few likely causes for an intermittent “wrong values while iterating” symptom on a Visual Basic/ADO Recordset: iteration logic errors (missing or double MoveNext), cursor/cursorLocation choices that don’t give a stable snapshot, reuse of module-level variables when a field is DBNull, ambiguous column names from joins, and reading the recordset while it’s still being filled (async). ’s request for code is the right move, and ’s pointer about resetting variables is relevant when fields can be NULL.

Checklist to narrow the fault (run these one at a time and log results):

  • Confirm the loop pattern: check EOF/BOF, call MoveFirst when appropriate, and ensure MoveNext is executed exactly once per iteration.
  • Add row-number logging (Debug.Print or append to a file) so the bad rows can be correlated with the source data.
  • Protect assignments from DBNull before converting or storing into typed variables (use IsNull in classic VB, IsDBNull/Convert.IsDBNull in .NET).
  • Avoid Fields(index) unless the column order is fixed; alias columns in SQL (use AS) so names are unique.
  • If relying on RecordCount, use a client-side/static cursor (CursorLocation = adUseClient, CursorType = adOpenStatic) or call MoveLast/MoveFirst to get an accurate count.
  • Snapshot the data if needed: arr = rs.GetRows() or fill a DataTable/array and iterate that instead of the live cursor.
  • Use Option Explicit and strongly typed variables so accidental reuse is caught at compile time.

Safe iteration example (classic ADO/VB):

' assume rs is an open ADODB.Recordset
If Not (rs Is Nothing) Then
  If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst
    Dim rowIndex As Long
    rowIndex = 1
    Do While Not rs.EOF
      Dim val As String
      If IsNull(rs!FieldName) Then
        val = ""
      Else
        val = CStr(rs!FieldName)
      End If
      Debug.Print "Row " & rowIndex & ": " & val
      rs.MoveNext
      rowIndex = rowIndex + 1
    Loop
  End If
End If

If the problem persists after these checks, the minimal reproducible snippet that shows connection, SQL, cursor settings, and the exact iteration loop will reveal whether the issue is iteration logic, cursor behavior, NULL handling, or column aliasing.

Recommended Answers

All 2 Replies

you will need to provide more info. Can you provide the code.

Member Avatar for Member #917609

Are you resetting any variables used back to "" if the event is reused?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.