1. Database value to List Box
Open a database, Connect it, retrieve the values with sql and populate the Listbox with them.

<%
set objConn=server.createobject("adodb.connection")
objConn.open "DSN=dbDSN;uid=username;pwd=password"
set rsValues=objConn.execute("select field
from table where )
%>
<Form>
<Select>
<%
do while not rsValues.eof %>
<option> <%=rsValues(0)%> </option>
<%
rsValues.movenext
loop
rsValues.close
set rsValues = nothing
objConn.close
set objConn=nothing
%>
</Select>
</form>

Explanation:

The code connectes the database, takes the values from the table and stores it in a recordset (rsValues). The values are added in to the option form filed one by one using the do…loop and the list has been populated. To use this code Modify the database connection details, and sql.

Back to code snippet home…

* Macronimous.com does not use information collected in this form for any marketing purposes. Check our privacy policy here.

Related Scripts

Show server variables

Show server variables

1. Show server variables This script displays all the server variables in a tabled format. <table width=”70%” align=”center”> <tr bgcolor=”#FF9900″> <td width=”25%”> <div align=”center”><font size=”2″><b><font

Include files dynamically

Include files dynamically

1. Include files dynamically You should use FileSystemObject to achieve this. <% Dim objFS,otf Set objFS = CreateObject(“Scripting.FileSystemObject”) Set otf = objFS.OpenTextFile(server.mappath(“/include/filename.asp”), 1, False) response.write