Ado Record in ASP
In Classic ASP, an ADO Record usually refers to a record in an ADO Recordset, which represents one row of data returned from a database query.
? What is an ADO Record?
It is a single row of data inside a
Recordset.You access its fields (columns) using the
Fieldscollection or shorthand likers("FieldName").You move through records using methods like
.MoveNext,.MovePrevious,.MoveFirst,.MoveLast.
? Example: Working with ADO Records in ASP
<%Dim conn, rs, sql' Open database connectionSet conn = Server.CreateObject("ADODB.Connection")conn.Open "Provider=SQLOLEDB;Data Source=SERVER;Initial Catalog=DB;User ID=USER;Password=PASS;"' Run SQL query to get recordssql = "SELECT UserID, Name, Email FROM Users"Set rs = conn.Execute(sql)' Loop through each recordDo Until rs.EOF Response.Write "User ID: " & rs("UserID") & "<br>" Response.Write "Name: " & rs("Name") & "<br>" Response.Write "Email: " & rs("Email") & "<hr>" rs.MoveNext ' Move to next recordLoop' Close recordset and connectionrs.CloseSet rs = Nothingconn.CloseSet conn = Nothing%>? Important Recordset Properties & Methods for Records
| Property/Method | Purpose |
|---|---|
.EOF | True if past the last record (end) |
.BOF | True if before the first record |
.MoveNext | Move cursor to next record |
.MovePrevious | Move cursor to previous record |
.MoveFirst | Move cursor to first record |
.MoveLast | Move cursor to last record |
.Fields | Collection of fields in the current record |
Tips:
Always check
.EOFbefore processing to avoid errors.Use
.Fields("FieldName")or("FieldName")to access data.Close the recordset and release objects to free resources.
Want a sample for adding, updating, or deleting records in ADO Recordsets?