Fill A ComboBox with DB Information

By ServerWatch Staff (Send Email)
Posted Apr 22, 1999

Joco Vieira

Something very usefull, that a beginner always want.

Something very usefull, that a beginner always want.

1. You just have to open the DB, and make a loop, that puts the code within the Combo. The Table from
     DataBase is really simple, something like TOPIC(ID As Number, NAME As Text)

<%	Dim objConnection ' the connection object
	Dim objRecordset ' the recordset object
	Set objConnection = Server.CreateObject("ADODB.Connection") ' create the Connection object
	objConnection.Open "show" ' open the DSN
       Set objRecordset = Server.CreateObject("ADODB.Recordset") ' creates the recordset object
       objRecordset.Open "SELECT ID, NAME FROM TOPIC ", objConnection ' execute the SQL statement that you want
       ' the statement that gives all the data you want to put in the Combo
 Choose from the combo : </font>:<select name="lstTopic" size="1">
<%  Do While Not objRecordset.EOF ' while we don't get the end of DataBase%>    
       <option VALUE="<%=objRecordset("ID")'we put the ID at Value
        ' this value is important to linked tables%>"> 
       <%=objRecordset("NAME")'here you put what the user will see, the name in this case%></option>
       <%objRecordset.MoveNext ' move to the next record
    Loop ' keep the loop
    objRecordset.Close ' close the recordset object
    Set objRecordset = Nothing ' clean the Recordset object

Page 1 of 1

Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date