</>
Skip to content
ASP lessons (23/40)

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

MethodDescription
OpenOpen recordset
CloseClose recordset
MoveNextNext record
MovePreviousPrevious record
MoveFirstFirst record
MoveLastLast record

Mini Practice

  1. Create connection
  2. Open recordset
  3. Use command object
  4. 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.