您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
如何从数据库得到一个列表表单
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 13:42:23
<HEAD>
<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-



更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |