ADO Recordset Guide: How to Use It
The Recordset object in ADO (ActiveX Data Objects) is used to access the result set returned from a database. It offers a range of properties and methods for fetching and manipulating data in a database.
- Instantiate a Recordset object:
- Create a new Recordset object using the Server.CreateObject method.
- Open the link:
- Execute “SELECT * FROM table name” using the connection object.
- The connection object here can either be a pre-existing connection object or a connection object can be directly created by specifying the connection string.
- Manipulating data:
- Move to the first record in the recordset:
rs.MoveFirst - Go to the last record in the recordset:
rs.MoveLast - Move to the next record:
rs.MoveNext - Move to the previous record:
rs.MovePrevious - Retrieve the field value of the current record:
value = rs(“field_name”) - Update the field value of the current record:
rs(“field name”) = value - Add a new record:
rs.AddNew
rs(“field name”) = value
rs.Update - Delete the current record:
rs.Delete - Close connection.
- Close the rs object and set it to Nothing.
The above is the basic usage of the ADO Recordset object, which can be flexibly applied according to actual needs.