Bilgisayar Bölümü ASP Kod ve Script Arşivi

Filling a list box from a database source

<TITLE>ASPHole - Fill List Box Example</TITLE>
Country: <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 "" & _
Do While Not oRS.EOF
mSelected = """"
If mCountry=trim(oRS(""Country"")) Then mSelected="" SELECTED""
<Input Type=SUBMIT>

Key points of the sample:

sPath Is used To construct the path To the database based On the home directory of the script. This means that the database must be In the same directory As the script., otherwise, Set sPath To the absolute path of the database.

The database Is assumed To a be an Access 2000 Database With a table Countries With a character field Country.

Forms are assumed To point at the same script which created it unless action Is specified.

The If mCountry=... statement Is used To insert the word SELECTED into the Option containing the previous country value, should one have been passed In by a submit.


ASP Kitabı


Faydalılar: Altın Fiyatları |Hediye Kolye | pırlanta fiyatları
Ana Sayfa  Sık Kullanılanlara Ekle   admin[at] | © 2006 - 2023