ADO Recordset properties and movement

Use this example to see the core idea, then work through the complete steps below. Code snippets are Classic ASP / VBScript or SQL Server T-SQL as labelled, not PHP.

Avoid reading past the end of a Recordset

VBScript example

If rs.EOF And rs.BOF Then
  Response.Write "No matching records"
Else
  Do While Not rs.EOF
    Response.Write Server.HTMLEncode(CStr(rs("name"))) & "<br>"
    rs.MoveNext
  Loop
End If

Assumes an open rs Recordset with a name field. An empty Recordset has both BOF and EOF set to True.

On this page — Show page sectionsHide page sections

An ADO Recordset keeps a current-row position while you browse query results. The cursor type used when the Recordset is opened determines which movement operations are available.

EOF

EOF becomes true after the current position moves beyond the last record. A forward-reading loop normally checks Do While Not rs.EOF before reading fields.

BOF

BOF indicates that the current position is before the first record. If a Recordset opens with no rows, both BOF and EOF are true and there is no current record.

MoveNext

MoveNext advances to the next row. Calling it when EOF is already true raises an error, so a normal loop stops when EOF becomes true.

MovePrevious, MoveFirst and MoveLast

Backward movement and direct first/last navigation require a Recordset/cursor that supports those operations. A forward-only Recordset is designed primarily for sequential MoveNext access.

RecordCount

RecordCount is cursor/provider dependent and can return -1 for a forward-only cursor. When you only need a count, a SQL COUNT(*) query is usually clearer and avoids opening a scrollable cursor just to count rows.

Open a forward-only Recordset

Use a forward-only Recordset for sequential display. The cursor usually does not support moving backward, and its RecordCount can be -1.

Count rows with a query

If you only need the number of records, use an aggregate query rather than moving the Recordset cursor.

SELECT COUNT(*) AS total_rows FROM emp_m;

Frequently asked questions

Do these examples require Classic ASP on IIS?
Yes. The server-side code uses VBScript and ADO components from Classic ASP; the .php file here is the Plus2Net tutorial wrapper.
Can I pass form input directly into SQL strings?
No. Validate it and bind it through ADO parameters rather than concatenating it into SQL text.
What should I do if no records match?
Check EOF before accessing fields and show a clear empty-result message.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer