ADO Record
The Record
object in ADO represents a single record in a data source. It is useful for accessing or updating a specific row of data without the need for a Recordset.
Key Topics
Accessing a Record
Example
<%
Dim conn, record
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=MyDatabase;User ID=myUser;Password=myPassword;"
Set record = Server.CreateObject("ADODB.Record")
record.Open "Employees", conn, 3, 3, 1
Response.Write("Name: " & record("EmployeeName").Value & "<br>")
record.Close
conn.Close
Set record = Nothing
Set conn = Nothing
%>
Explanation: This example demonstrates accessing a specific record from the Employees
table using the Record
object.
Updating a Record
Example
<%
record("Department").Value = "HR"
record.Update
Response.Write("Record updated successfully.")
%>
Explanation: This example shows how to update a field value in a specific record and save the changes using the Update
method.
Key Takeaways
- The
Record
object is ideal for single-row access and updates. - Use
Open
to load a specific record andUpdate
to save changes. - Efficient for scenarios requiring minimal data access or updates.