Solved

Combining the results of 3 or 4 queries done on an ASP page into a single displayed table on a web page using VB

Posted on 2004-08-11
10
188 Views
Last Modified: 2010-05-02
I am running an LDAP query against our Active Directory global catalog. Since we are running mixed mode, I have to do a separate query for each child domain but I want the results to be displayed in a single table that I can sort by last name. This is essentially a phone list lookup using our active directory as a database. I can do the data dip but I don't know how to append to the array I created...

Here is what I am doing: It only displays the last data from the last getrows()
I will want to dip into 6 separate servers and have all aggregated into a single, sorted, combined table....<%
   
   Dim RS
   Dim RS2
   set Conn = CreateObject("ADODB.Connection")
   set Command = CreateObject("ADODB.Command")
   Conn.Provider = "ADsDSOObject"
   Conn.Open "Ads Provider"
   Set RS = Server.CreateObject("ADODB.Recordset")
   Set RS2 = Server.CreateObject("ADODB.Recordset")
   set Command.ActiveConnection = Conn  'set the active connection

' Now we will loop through the results of our query
'   and build a table to display the Global Address List
 

'Assumes there is an open Connection object, Conn

'Create a Recordset
RS2.Open "SELECT cn,telephonenumber,mobile,ipphone,physicalDeliveryOfficeName,title  FROM 'LDAP://Server1:389/CN=Users,DC=parentdomain,DC=com' WHERE objectClass='*' and telephonenumber > '0'   ORDER BY cn " , Conn
RS.Open "SELECT cn,telephonenumber,mobile,ipphone,physicalDeliveryOfficeName,title  FROM 'LDAP://server2:389/CN=Users,dc=child,DC=parentdomain,DC=com' WHERE objectClass='*' and telephonenumber > '0'   ORDER BY cn " , Conn
'Now, read the Recordset into a 2d array
Dim aTable1Values
aTable1Values = RS.GetRows()
aTable1Values = RS2.GetRows()


 
Dim iRowLoop, iColLoop
For iRowLoop = 0 to UBound(aTable1Values, 2)
  For iColLoop = 0 to UBound(aTable1Values, 1)
%>

<%

  Next 'iColLoop

Next 'iRowLoop

numrows=ubound(aTable1Values,2)
fld_Name=5
fld_OfficePhone=4
fld_CellPhone=3
fld_IPPhone=2
fld_location=1
fld_Title=0


FOR rowcounter= 0 TO numrows
   response.write "<tr>" & vbcrlf
   name=aTable1Values(fld_name,rowcounter)
   OfficePhone=aTable1Values(fld_OfficePhone,rowcounter)
   CellPhone=aTable1Values(fld_CellPhone,rowcounter)
   IPPhone=aTable1Values(fld_IPPhone,rowcounter)
   location=aTable1Values(fld_location,rowcounter)
   Title=aTable1Values(fld_Title,rowcounter)
 
   name=cleanfield(name)
   OfficePhone=cleanfield(OfficePhone)
   CellPhone=cleanfield(CellPhone)
   IPPhone=cleanfield(IPPhone)
   Location=cleanfield(Location)
   Title=cleanfield(Title)
%>
<TD><% response.write "<td valign=top>" & name & "</td>" & vbcrlf %>      
<TD><% response.write "<td valign=top>" & OfficePhone & "</td>" & vbcrlf   %>  
<TD><% response.write "<td valign=top>" & CellPhone & "</td>" & vbcrlf   %>
<TD><% response.write "<td valign=top>" & IPPhone & "</td>" & vbcrlf   %>
<TD><% response.write "<td valign=top>" & Location & "</td>" & vbcrlf%>
<TD><% response.write "<td valign=top>" & Title & "</td>" & vbcrlf   %>  


<%
NEXT
%>


</body></html>
<%
SUB CloseAll
   rs.close
   set rs=nothing
   rs2.close
   set rs2=nothing
   conn.close
   set conn=nothing
END SUB

FUNCTION CleanField(parm1)
      cleanfield=parm1
      if isnull(parm1) then
         cleanfield="&nbsp;"
      end if
      if trim(parm1)="" then
         cleanfield="&nbsp;"
      end if
END FUNCTION
%>
0
Comment
Question by:chgrec
10 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
You could try changing your first query to this:

SELECT cn,telephonenumber,mobile,ipphone,physicalDeliveryOfficeName,title  FROM 'LDAP://Server1:389/CN=Users,DC=parentdomain,DC=com' WHERE objectClass='*' and telephonenumber > '0'   ORDER BY cn UNION SELECT cn,telephonenumber,mobile,ipphone,physicalDeliveryOfficeName,title  FROM 'LDAP://server2:389/CN=Users,dc=child,DC=parentdomain,DC=com' WHERE objectClass='*' and telephonenumber > '0'   ORDER BY cn

Notice it uses the UNION statement to combine two queries into one recordset.  This would work on database tables, not sure if it will work with LDAP.  But you can always try it.

Hope this helps.
0
 

Author Comment

by:chgrec
Comment Utility
Thanks, but apparently LDAP queries dont work that way....I have tried several sql style join type statements (including yours) and they dont work.....
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
LDAP does not support UNION clauses.  You will have to create a recordset on the fly and append from your two queries or do the same with your arrays.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
Here is a document that describes what SQL clauses it does support:
SQL Dialect
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/sql_dialect.asp
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:chgrec
Comment Utility
Thats why I posted the question, I need to know how to take multiple queries, append the data in an array for sorting and display in a single  table....
How do I append an array?
0
 

Author Comment

by:chgrec
Comment Utility
how do I do a request a refund? no one answered the question and I found out how to do what I wanted using port 3268 instead of port 389....
0
 
LVL 75

Expert Comment

by:Anthony Perkins
Comment Utility
>>how do I do a request a refund?<<
Try clicking on the link Dan posted.
0
 

Accepted Solution

by:
modulo earned 0 total points
Comment Utility
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now