To read the article online, visit

Fill A ComboBox with DB Information
By Joao Vieira

Filling a combo box with results a database query is something that ASP developers need to do often. This script will present an example of how to do just this. It's something every beginner should read and implement!

First you must open the DB, execute your query, and store the results in a recordset. Once we have that recordset, we will make a loop that puts the values into the combo box. For this example, let's say that the table we're querying has the following structure:


Here is the script. It's pretty simple to follow along. Happy Programming!

    ' the connection object
    Dim objConnection
    ' the recordset object
    Dim objRecordset

    ' create the Connection object
    Set objConnection = Server.CreateObject("ADODB.Connection")
    ' open the DSN

    ' creates the recordset object
    Set objRecordset = Server.CreateObject("ADODB.Recordset")

    ' SQL String for query     Dim strSQL

    ' execute the SQL statement that you want
    ' The query should return all the data you'll
    ' need in your combo box
    objRecordset.Open strSQL, objConnection

    <FORM ACTION="someurl.asp" METHOD=POST>
        Choose from the combo:
        select name="lstTopic" size="1">
        ' while we don't get the end of DataBase
        Do While Not objRecordset.EOF
            'we put the ID at Value
            ' this value is important to linked tables
            <option VALUE="<%=objRecordset("ID")%>">
                <!-- This is what will appear in the combo box -->
            ' Move to the next record...
        Loop ' keep the loop


    ' close the recordset object

    ' clean the Recordset object
    Set objRecordset = Nothing

Article Information
Article Title: Filling a ComboBox with DB Information
Article Author: Joao Vieira
Published Date: Thursday, April 15, 1999
Article URL:

Copyright 2018 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers