1<head>
2<title>ASPHole - Fill List Box Example</title>
3</head>
1<body>
2<form method="POST">
3Country: <select name="Country">
' Construct path to database
sPath = Request.ServerVariables("Path_Translated")
sPath = Left(sPath,InStrRev(sPath,"")) & "Countries.mdb"
'
' Open Connection & Recordset
set oSample = Server.CreateObject("ADODB.Connection")
oSample.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=TRUE;" & _
"Data Source=" & sPath, "Admin", ""
'
' Check for default...
mCountry = Trim(Request("Country"))
'
' Create the List
Set oRS=oSample.Execute _
("SELECT ID,COUNTRY " & _
"FROM COUNTRIES " & _
"ORDER BY ID")
DO WHILE NOT oRS.EOF
mSelected = ""
IF mCountry=trim(oRS("Country")) then mSelected=" SELECTED"
1<option``` =mselected="" ```="">```
2=oRS("Country")
1
2oRS.MoveNext
3Loop
</option```></select><br/> <input type="SUBMIT"/> </form> </body>
1Key points of the sample:
2
3sPath is used to construct the path to the database based on the home directory of the script. This means
4that the database must be in the same directory as the script., otherwise, set sPath to the absolute path
5of the database.
6
7The database is assumed to a be an Access 2000 Database with a table Countries with a character field
8Country.
9
10Forms are assumed to point at the same script which created it unless action is specified.
11
12The IF mCountry=... statement is used to insert the word SELECTED into the OPTION containing the previous
13country value, should one have been passed in by a submit.
14
15If you have problems running this script, your database drivers may be out of date. Go to
16http://www.microsoft.com/data for the current MDAC RTM.
17
18-END-