根据使用经典 ASP 从任何下拉列表中选择的选项填充多个下拉列表中的字段

Populate fields in multiple dropdowns based on option selected from any drop down list using Classic ASP

我找到了 this 填充一个组合框的解决方案, 但是如果我需要更改多个组合框列表怎么办?

最佳表现是什么?

  1. 运行 每次与 Sql
  2. 的新连接打开时,每个组合框都需要查询相同的代码
  3. 获取所有行到 vbscript 数组并使用它

  4. 在一次查询中发送多个 select 语句

strSQL = "Select Distinct Make From Cars; Select Distinct Model From Cars;...;"

但是我不知道如何获得对变量或数组的响应 我收到错误

Microsoft JET Database Engine error '80040e14'

Characters found after end of SQL statement.

我不知道哪个最快。我猜是将所有查询一次传递给数据库,然后处理返回的各种 tables。

就个人而言,我最担心的是维护和编辑代码的效率,而不是执行,因为除非在特殊情况下,否则您会注意到它们之间的差别很小。

在此基础上,我会查询、获取数据并一次填充一个下拉列表,然后看看它是如何运行并等待证明这是不可能完成的。

使用这种方法,您甚至可以使用查询(或 table 和列)调用的子函数或函数,将结果构建到下拉列表中。

嗯,根据你的例子,我最初会做这样的事情:

<select name="First">
<%
set rsRecordSet=Server.CreateObject("ADODB.recordset")
rsRecordSet.Open "Select distinct ID,FirstThing FROM FirstTable", connection
While not rsRecordSet.EOF
    %>
    <OPTION VALUE="<%=rsRecordSet("ID")%>"><%=rsRecordSet("FirstThing")%></OPTION> 
    <% 
    rsRecordSet.MoveNext 
Wend 
rsRecordSet.Close
Set rsRecordSet= nothing 
%>
</select> 

<select name="Second">
<%
set rsRecordSet=Server.CreateObject("ADODB.recordset")
rsRecordSet.Open "Select distinct ID,SecondThing FROM SecondTable", connection
While not rsRecordSet.EOF
    %>
    <OPTION VALUE="<%=rsRecordSet("ID")%>"><%=rsRecordSet("SecondThing")%></OPTION> 
    <% 
    rsRecordSet.MoveNext 
Wend 
rsRecordSet.Close
Set rsRecordSet= nothing 
%>
</select> 

<select name="Third">
<%
set rsRecordSet=Server.CreateObject("ADODB.recordset")
rsRecordSet.Open "Select distinct ID,ThirdThing FROM ThirdTable", connection
While not rsRecordSet.EOF
    %>
    <OPTION VALUE="<%=rsRecordSet("ID")%>"><%=rsRecordSet("ThirdThing")%></OPTION> 
    <% 
    rsRecordSet.MoveNext 
Wend 
rsRecordSet.Close
Set rsRecordSet= nothing 
%>
</select> 

方式 №4.

运行 一切都在一个查询中,结果将在一个数据集中。

strSQL = "Select Distinct Make as Value, 'S1' as SelectionNumber From Cars union all Select Distinct Model as Value, 'S2' as SelectionNumber From Cars"

在这种情况下,您会知道 SelectionNumber 字段包含您的查询 ID...

What is best performance will be?

我建议您使用 SQL Server Profiler 来衡量您的查询速度。