如何从数据库得到一个列表表单
2008-02-23 09:47:11来源:互联网 阅读 ()
<TITLE>ASPHole - Fill List Box Example</TITLE>
</HEAD>
<BODY>
<FORM METHOD=POST>
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 " & _
"FROM COUNTRIES " & _
"ORDER BY ID")
DO WHILE NOT oRS.EOF
mSelected = ""
IF mCountry=trim(oRS("Country")) then mSelected=" SELECTED"
%>
<OPTION<%=mSelected%>><%=oRS("Country")%></OPTION>
<%
oRS.MoveNext
Loop
%>
</SELECT><BR>
<INPUT TYPE=SUBMIT>
</FORM>
</BODY>
</HTML>
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.
If you have problems running this script, your database drivers may be out of date. Go to
http://www.microsoft.com/data for the current MDAC RTM.
-END-
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash