当前位置: 首页 > 图文教程 > 网络编程 > ASP > 如何从数据库得到一个列表表单

ASP
使用ASP中的VB ActiveX.dll文件
用ADO的COMMAND对象实现对WEB数据库动态数据查询的方法
在ASP中使用简单Java类
借助组件使用asp连接informix全方案
用ADSI编程实现IIS中建立虚拟目录
不刷新页面筛选数据库中的数据
使用ISAPI过滤器增强IIS的功能
利用J2ME与ASP建立数据库连接
用通ASP直接获取用户真实IP地址
用ASP编写计数器的优化方法
通过ASP远程注册自己的组件
检测IP地址是否真正合法的函数
用asp做access的远程接口
错误80004005信息处理方法
ASP学习:urldecode 方法补遗
在HTML页面中实现点击数统计
ASP字数计算函数
用ASP随机生成文件名的函数
单页面判断浏览器是否接受 Cookies
存储过程介绍及asp+存储过程的使用

ASP 中的 如何从数据库得到一个列表表单


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 36 ::
收藏到网摘: n/a

  <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-