ADO searches can be easily incorporated into ASPs using the information in this chapter and Chapter 20. 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 25-1 is what the final result should look like for a new server with very few users.
Figure 25-1. A navigable table on a web page populated by ADO
This ASP 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 "", _ "CN=Administrator,CN=Users,dc=mycorp,dc=com", "" Set objRS = objConn.Execute _ ("<LDAP://dc=mycorp,dc=com>;" _ & "(objectClass=User);Name,ADsPath;SubTree") %>
Having done this, we can now begin to create the table. The table definition must 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:
<TR> <% For Each adoField In objRS.Fields ...