Did you find this useful?
Socialize it today.


Introduction to ADO

Wednesday, September 19, 2012

tags ADO

Microsoft's ActiveX Data Objects (ADO) was introduced in 1996 by Microsoft. It is a set of Component Object Model (COM) objects for accessing data sources. It provides a middleware layer between programming languages and OLE DB. ADO allows a developer to write programs that access data without knowing how the database is implemented. While no knowledge of SQL is required to access a database when using ADO, it is common for to directly execute SQL commands. In the case of web development, simply put, ADO can be used to access databases from your web pages.


Pre-Reqs

Before you continue to learn more about ADO, you should have a basic understanding of HTML, ASP, and SQL.


How to Implement ADO

In the next upcoming tutorials, we will take a deeper look into how ADO can be incorporated into your ASP web applications to access a data source. However, to simplify the process, the following high level steps are executed:

  1. Create an ADO connection to a database
  2. Create an ADO recordset to receive data
  3. Open the database connection
  4. Open the recordset
  5. Extract the data you need from the recordset
  6. Close the recordset
  7. Close the connection

Example

In this example, we are going to connect to a table in a MySQL database called "Employees". We will run a SQL Select Query and capture the results in a recordset. Finally, extract the information from the record set and display the results in a table.

<!DOCTYPE html>
<html>
<head>
    <title>My Page</title>
</head>
<body>

<% 
Dim connection, recordset, datasource, sql
Set connection=Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.recordset")
datasource = "Driver={MySQL ODBC 3.51 Driver};SERVER=db-hostname;DATABASE=db-name;UID=userID;PWD=password"
sql = "SELECT empName, empTitle FROM employees"
connection.Open datasource
recordset.Open sql, connection
%> 
<table style="width:500px;">
  <tr>
  <%for each x in recordset.Fields
        Response.Write("<th>" & x.name & "</th>")
  next%>
  </tr>
  <%do until recordset.EOF%>
    <tr>
    <%for each x in recordset.Fields%>
      <td><%Response.Write(x.value)%></td>
    <%next
    recordset.MoveNext%>
    </tr>
  <%loop
  recordset.close
  connection.close
  Set oRS=nothing
  Set oConn=nothing
  %>
</table>

</body>
</html>

In the previous example, you could easily connect to a different data source simply by changing the value of the 'datasource' value. Microsoft's philosophy behind ADO, as well as a series of related technologies, is Universal Data Access (UDA). UDA is not a product, but rather a strategy for simplifying the complexity of data access. UDA is meant to eliminate the need to convert existing data from one proprietary format to another.

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

ADO Programmers Reference ADO Programming for Dummies ADO: ActiveX Data Objects