ASP — ADO
Connection Object
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB;Data Source=server;Initial Catalog=mydb;"
' Close connection
conn.Close
Set conn = Nothing
%>
Recordset Object
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM users", conn, 1, 1
Do While Not rs.EOF
Response.Write(rs.Fields("name").Value & "<br>")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
%>
Command Object
<%
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * FROM users WHERE age > ?"
cmd.Parameters.Append cmd.CreateParameter("age", 3, 1, , 18)
Set rs = cmd.Execute
%>
Recordset Methods
| Method | Description |
|---|---|
| Open | Open recordset |
| Close | Close recordset |
| MoveNext | Next record |
| MovePrevious | Previous record |
| MoveFirst | First record |
| MoveLast | Last record |
Mini Practice
- Create connection
- Open recordset
- Use command object
- Navigate records
Up Next
Continue with SQL — SQL operations in ASP.
Related Topics
Frequently Asked Questions about ADO
What is ADO in ASP?
ADO is a fundamental concept in ASP. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn ADO?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn ADO.
Why is ADO important in ASP?
ADO is essential for ASP development. Understanding this concept will help you write better code and solve real-world problems more effectively.