Incorporating Searches into ASP

ADO searches can be easily incorporated into ASPs using the information in this chapter and Chapter 22. In this first example, we will navigate through a resultset using server-side scripts in order to populate a table that gets created dynamically. To make it easier to understand, Figure 28-1 is what the final result should look like for a new server with very few users.

A navigable table on a web page populated by ADO

Figure 28-1. A navigable table on a web page populated by ADO

This ASP page includes all its code in the body of the web page. To begin with, we must retrieve the resultset:

<%
  Set objConn = CreateObject("ADODB.Connection")
  objConn.Provider = "ADSDSOObject"
  objConn.Open "", _
    "mycorp\administrator", "My-admin-password!"

  Set objRS = objConn.Execute _
    ("<LDAP://dc=mycorp,dc=com>;" _
      & "(&(objectCategory=person)(objectClass=user));Name,ADsPath;SubTree")
%>

Having done this, we can now begin to create the table. The table definition can include the number of columns. Even though we know that we are retrieving two columns, we will include the value returned from the query rather than hardcoding a value of 2 into the table so that we can extend the page later. The table definition then looks like this:

<TABLE BORDER=1 COLS=<% = objRS.Fields.Count%>>

Now we need to include column headings. Again, if we take these directly from the query, then we can expand the query much more easily later:

Get Active Directory, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.