Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort problem in VBscript/ASP

Status
Not open for further replies.

woodrasj

IS-IT--Management
Jun 17, 2002
27
0
0
US
I was asked to make a Phone search/sort webpage for my company using the information in active directory. Not a problem. I am having a problem though with my code where I try to sort on more than one part of the display that it returns no results. If I only use one part to sort on it works just fine but with both location and last name it returns no results.

The code follows and this page is just called from another page and in this case with no name passed to it.

Wasn't sure whether to post this here or in ASP forum but I think it is an ADO VBscript problem. If anybody is an ADO expert the help would be greatly appreciated.
Code:
<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>Phone Number Search Results</TITLE>
<LINK rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;styles.css&quot;>
</HEAD>
<BODY>
<h1>Phone Number Search Results</h1>
<P>Search results for &quot;<%=Request.QueryString (&quot;Name&quot;)%>&quot;</P>
<P><A href=&quot;default.asp&quot;>Search again</A></P>
<TABLE class=ResultsTable>
    <THEAD>
    <TR>
        <TH>Name</TH>
        <TH>Phone Number</TH>
	<TH>Department</TH>
	<TH>Location</TH></TR>
    </THEAD>
    <TBODY>
<%
' Build the query string
' First, need to discover the local global catalog server
Set adsRootDSE = GetObject(&quot;GC://RootDSE&quot;)

' Form a ADsPath string to the DN of the root of the 
' Active Directory forest 
strADsPath = &quot;GC://&quot; & adsRootDSE.Get(&quot;rootDomainNamingContext&quot;)

' Wrap the ADsPath with angle brackets to form the base string
strBase = &quot;<&quot; & strADsPath & &quot;>&quot;

' Release the ADSI object, no longer needed
Set adsRootDSE = Nothing

' Specify the LDAP filter
' First, indicate the category of objects to be searched 
' (all people, not just users)
strObjects = &quot;(objectCategory=person)&quot;

' Get the name to search for from the URL
strPerson = Request.QueryString(&quot;Name&quot;)

' If the given name is blank, then filter on all people
If (strPerson = &quot;&quot;) Then
    strName = &quot;(sn=*)&quot;
Else
    strName = &quot;(sn=&quot; & strPerson & &quot;*)&quot;
End If

' Add the two filters together
strFilter = &quot;(&&quot; & strObjects & strName & &quot;)&quot;

' Set the attributes for the recordset to contain
' We're interested in the common name, telephone number, surname, given name, dept, and location
strAttributes = &quot;cn,telephoneNumber,sn,givenname,department,l&quot;

' Specify the scope (base, onelevel, subtree)
strScope = &quot;subtree&quot;

' Create ADO connection using the ADSI OLE DB provider
Set adoConnection = Server.CreateObject (&quot;ADODB.Connection&quot;)
adoConnection.Open &quot;Provider=ADsDSOObject;&quot;

' Create ADO commmand object and associate with the connection
Set adoCommand = Server.CreateObject (&quot;ADODB.Command&quot;)
adoCommand.ActiveConnection = adoConnection

' Create the command string using the four parts
adoCommand.CommandText = strBase & &quot;;&quot; & strFilter & &quot;;&quot; & _
    strAttributes & &quot;;&quot; & strScope

' Set the number of records in the recordset logical page
adoCommand.Properties(&quot;Page Size&quot;) = 20

' Set the maximum result size
adoCommand.Properties(&quot;Size Limit&quot;) = 20

' Sort the results based on the l (location) and sn (Surname) attributes
adoCommand.Properties(&quot;Sort On&quot;) = &quot;l, sn&quot;



' Execute the query for the user in the directory
Set adoRecordSet = adoCommand.Execute

If adoRecordSet.EOF Then
    Response.Write &quot;</TBODY><THEAD><TH>No names found</TH></THEAD>&quot;
Else
    ' Loop through all the returned records
    While Not adoRecordSet.EOF
        ' Display the row using the selected fields
        Response.Write &quot;<TR>&quot;
        Response.Write &quot;<TD>&quot; & adoRecordSet.Fields(&quot;sn&quot;) & &quot;,&quot; & _
			adoRecordset.Fields(&quot;givenname&quot;) & &quot;</TD>&quot;

        ' Check to see if telephone number field is null
        If IsNull( adoRecordSet.Fields(&quot;telephoneNumber&quot;) ) Then
            Response.Write &quot;<TD>(number not listed)</TD>&quot;
        Else
        ' Retrieve the telephone number and add to the display line
        Response.Write &quot;<TD>&quot; & _
            adoRecordSet.Fields(&quot;telephoneNumber&quot;) & &quot;</TD>&quot;
        End If
	
	'Retriece department and location and add to the display line
	Response.Write &quot;<TD>&quot; & adoRecordset.Fields(&quot;department&quot;) & &quot;</TD>&quot;
	Response.Write &quot;<TD>&quot; & adoRecordset.Fields(&quot;l&quot;) & &quot;</TD>&quot;
	
        ' End the row
        Response.Write &quot;</TR>&quot;

        ' Advance to the next record
        adoRecordSet.MoveNext
    Wend
End If

' Close the ADO connection
adoConnection.Close
%>
</TBODY>
</TABLE>
</BODY>
</HTML>

Thanks in advance,

John Woodraska
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top