I am new to ASP, but know SQL and VBA well. I want to show the results of a query in a combo box on an asp page. If someone could help me with this code, it would be greatly appreciated.
<%
Dim con, rs, sql
Set con = Server.CreateObject("ADODB.Connection"
con.Open connection_string
sql = "your sql statement to select records"
Set rs = Server.CreateObject("ADODB.Recordset"
rs.Open con, sql
%>
<select name="lstList">
<%
Do Until rs.EOF
Response.Write "<option value='" & rs("value field" & "'>" & rs("display field"
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set con = Nothing
%>
</select>
In the above, you have to create you connection string to open a connection to your database. (Let me know if you need an example).
Also, in the combo box, I am assuming (as this is what I normally do) that you want one thing displayed in the combo box, but another thing to act as the value (eg display names in the combo box, but return the userID as the value of the selection), so will need to select these two fields in the sql statement.
If you need clarification on any of the above, let me know.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.