Go Back To List Basic Classic ASP |
Classic ASP Database Driven Select Menu (Dropdown Menu) |
Next Article Classic ASP Database Driven Select Menu to insert data |
Coding Article #: 40 - Published On: August 05, 2012 @ 19:07:16 PM - Last Updated on: August 05, 2012
This article has been Favorited 35 timesJoin today, and add this to your favorites.
Share With Friends (Updated 6-8-2010)
In this demonstration, you will be able to code your Select Menu loading data from your database quickly and easily. Using this technique is the best way to get your data loaded quickly.
View Live Example«
Next, we need to get our DATABASE connection.
Below, you can choose to use either JET or Microsoft Access Driver.
Create our Select Statement. We need to get the records from our database, to display to our page.
Next, we create our select Field, and polulate it with our database records.
Always remembering to close our the recordset and the database connection at the end.
View Live Example«
Next, we need to get our DATABASE connection.
Below, you can choose to use either JET or Microsoft Access Driver.
<%
Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
Server.MapPath ("dd.mdb") & ";"
objConn.Open
' OR
objConn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" & _
Server.MapPath ("dd.mdb")
%>
Create our Select Statement. We need to get the records from our database, to display to our page.
<%
' Create the Command to start your SQL and then your RecordSet (rsDD)
Set sqlDD = Server.CreateObject("ADODB.Command")
sqlDD.ActiveConnection=objConn
sqlDD.Prepared = true
sqlDD.commandtext="SELECT ddid, ddname from myTable"
set rsDD = sqlDD.execute
%>
Next, we create our select Field, and polulate it with our database records.
Always remembering to close our the recordset and the database connection at the end.
<select>
<option value="0">Choose</option>
<%if not rsDD.eof then
while not rsDD.eof
id = rsDD("ddid")
ddName = rsDD("ddName")%>
<option value="<%=id%>"><%=ddName%></option>
<%rsDD.movenext
wend
end if
rsDD.close
set rsDD = nothing
objConn.close
set objConn = Nothing%>
</select>
Post to Facebook about: Classic ASP Database Driven Select Menu (Dropdown Menu)