如何从数据库得到一个列表表单
类别: ASP教程
<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>
<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>
- 上一篇: 灵活实用的页面广告实例
- 下一篇: 使用COOKIE来跟踪用户
-= 资 源 教 程 =-
文 章 搜 索