我有这个代码用于为管理员工作的页面填充组合框,允许他们搜索已根据他们的技能水平预订的课程,但是看到它是我的A2计算我决定填充组合表格中包含值的框,遗憾的是,正如预期的那样,它显示了在表格上输入的相同值的重新出现,因此如何调整我当前的代码(ref microsoft dev site)基本上相当于SELECT DISTINCT但仍然填充组合框。感谢
<HTML>
<BODY>
<BR>This is an HTML ListBox<BR>
<SELECT NAME="ListBox" SIZE=1>
<% Set conn = Server.CreateObject("ADODB.Connection") %>
<% conn.Open "DSN=AdvWorks" ' connect to the database %>
<% Set rs = conn.Execute("SELECT City FROM Customers") %>
<% Do While Not rs.EOF ' define the ListBox OPTIONs %>
<OPTION VALUE="<%= rs("City") %>"> <%= rs("City") %>
<% rs.MoveNext %>
<% Loop %>
<% rs.Close %>
<% conn.Close %>
</SELECT>
</BODY>
</HTML>`
答案 0 :(得分:0)
执行SELECT DISTINCT的方法是做一个SELECT DISTINCT。
(每一行的关闭和打开代码是什么?)
<p>Select city: <select name="listbox" size="1">
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=AdvWorks" ' connect to the database
'- construct SQL query (your actual query could be much, much more
' complicated than this):
Dim sql : sql = "SELECT DISTINCT City FROM Customers"
Set rs = conn.Execute(sql)
Do While Not rs.EOF ' define the ListBox OPTIONs
Response.Write "<option value=""" & rs("City") & """"
'- you can put code here to test if this should be the selected option
' (if yes, you'd write out " selected=""selected""")
Response.Write ">" & rs("City") & "</option>"
rs.MoveNext
Loop
rs.Close
conn.Close
%>
</select></p>