Asp classic 使用ASP删除下拉列表中的重复项

Asp classic 使用ASP删除下拉列表中的重复项,asp-classic,active-directory,Asp Classic,Active Directory,我有一段代码,它将显示一个服务区域列表,然后,当您选择一个服务区域时,它将在第二个下拉框中返回一个部门列表。我有以下代码: <%@ Language="VBScript"%> <% response.Buffer = TRUE 'Defines the variables and objects dim ADUser, RecordList, intOne, intTwo, intThree, companies, service_area, department, a

我有一段代码,它将显示一个服务区域列表,然后,当您选择一个服务区域时,它将在第二个下拉框中返回一个部门列表。我有以下代码:

 <%@ Language="VBScript"%>
 <% response.Buffer = TRUE
 'Defines the variables and objects
 dim ADUser, RecordList, intOne, intTwo, intThree, companies, service_area, department, arrComp
 'Assigns the objComp and objDept variables to Scripting Dictionary objects
 %>
 <!--#include file="includes/functions.asp"-->
 <!--#include file="includes/display.asp"-->
 <!--#include file="includes/results.asp"-->
 <!--#include file="includes/timer.asp"-->
 <h1>Organisational Structure</h1>
 <div class="commandspace">
 <p class="infotext">The org structure can be viewed with or without staff, indented or left justified.</p>
 </div>
 <% 
 ADUser = "LDAP://RBCTHDC1/OU=Staff,OU=Users,DC=example,DC=internal"
 ' Make AD connection and run query
 Set objCon = Server.CreateObject("ADODB.Connection")
 objCon.provider ="ADsDSOObject"
 objCon.Properties("User ID") = "DOMAIN\username"
 objCon.Properties("Password") = "Password"
 objCon.Properties("Encrypt Password") = TRUE
 objCon.open "Active Directory Provider"
 Set objCom = CreateObject("ADODB.Command")
 Set objCom.ActiveConnection = objCon 
 objCom.CommandText ="select company FROM '"& ADUser &"' where company ='*'" 
 Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
 companies = objRS.GetRows()
 set arrComp = Server.CreateObject("Scripting.Dictionary")
 for intOne = 0 to UBound(companies,2)
      if not arrComp.exists(companies(0, intOne)) then
      arrComp.add companies(0, intOne), companies(0, intOne)
      end if
 next 
 response.write "<form action='index.asp?View=Structure' method='POST'>"
 response.write "<select id='service_area' name='service_area' onChange='showTeams(this.value)'>"
 response.write "<option>Please Select</option>"
 for intTwo = 0 to arrComp.Count
      response.write "<option value='"& Server.URLEncode(arrComp.Item(intTwo)) &"'>" & arrComp.Item(intTwo) & "</option>"  & VBCrlF
 next
 response.write "</select>"   & VBCrlF
 response.write "<span class='structure-spacing'></span>"  & VBCrlF
 response.write "<select id='department' name='department'></select>"  & VBCrlF
 response.write "<span class='structure-spacing'></span>"  & VBCrlF
 response.write "<input type='submit' name='submit' id='submit'>"  & VBCrlF
 response.write "</form>"  & VBCrlF
 if request.form("submit")="Submit" then
      service_area = request.form("service_area")
      department = request.form("department")
      if service_area = "Please Select" then 

      response.write "<p>Service area cannot be left empty</p>"

      end if

      if IsEmpty(department) then 

      response.write "<p>Department cannot be left empty</p>"

      end if
        objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where department = '" & department & "' ORDER BY department" 
 else
      objCom.CommandText ="select company, department, title, cn FROM '"& ADUser &"' where company ='*' ORDER BY department" 
 end if
 Set objRS = objCom.Execute 'Creates an object and runs the LDAP query
 RecordList = objRS.GetRows()
 response.write "<table>"  & VBCrlF
 response.write "<thead>"  & VBCrlF
 response.write "<tr>"  & VBCrlF
 response.write "<th>Service Area</th>"  & VBCrlF
 response.write "<th>Department</th>"  & VBCrlF
 response.write "<th>Job Title</th>"  & VBCrlF
 response.write "<th>Name</th>"  & VBCrlF
 response.write "</tr>"  & VBCrlF
 response.write "</thead>"  & VBCrlF
 response.write "<tbody>"  & VBCrlF
 for intThree = 0 to UBound(RecordList,2)
      response.write "<tr>"  & VBCrlF
      response.write "<td>" & RecordList(3, intThree) & "</td>"  & VBCrlF
      response.write "<td>" & RecordList(2, intThree) & "</td>"  & VBCrlF
      response.write "<td>" & RecordList(1, intThree) & "</td>"  & VBCrlF
      response.write "<td>" & RecordList(0, intThree) & "</td>"  & VBCrlF
      response.write "</tr>"  & VBCrlF
 next
 response.write "</tbody>"  & VBCrlF
 response.write "</table>"  & VBCrlF
 objRS.Close
 objCon.Close
 Set objCon = Nothing
 Set objCom = Nothing
 %>     

我找不到删除重复条目的方法。使用脚本字典,我得到一个空的下拉框。它不返回服务区域列表,而不返回任何内容-只返回一个空选项值

您可以在SQL中选择DISTINCT,或者在底部的循环语句中创建一个临时公司或部门值。然后在循环的顶部将当前公司或部门与此临时公司或部门进行比较。如果它们是相同的意思,那么由于您的订单,在之前有两个重复的条目,则不响应。写下该记录行的结果。我现在已经解决了它