首页 | 免费域名 | 个人服务器 | 一流信息监控拦截系统 | 虚拟主机知识库 | ASP 空间 | ASP技术大全 | 下载中心 | 客户服务中心
  7i24 > ASP技术大全 > ASP与数据库 >
    7i24 .Com  
  将数据库的内容放到下拉列表中

7i24.Com不停为您服务
将数据库的内容放到下拉列表中

<%
Dim objDC, objRS

' Create and establish data connection
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30

'Use this line to use Access
'objDC.Open "DBQ=" & Server.MapPath("database.mdb") & ";Driver=
{Microsoft Access Driver
(*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;", "username", "pas
sword"

'Our SQL Server code - use above line to use sample on your server
objDC.Open Application("SQLConnString"), Application("SQLUsername"),
Application("SQLPassword")


' Create recordset and retrieve values using the open connection
Set objRS = Server.CreateObject("ADODB.Recordset")
' Opening record set with a forward-only cursor (the 0) and in read-
only mode (the 1)

' If a request for a specific id comes in, then do it o/w just show
pulldown
If Len(Request.QueryString("id")) <> 0 Then
' request record for requested id
objRS.Open "SELECT * FROM sample WHERE id=" &
Request.QueryString("id"), objDC, 0, 1
' Show selected record
If Not objRS.EOF Then
objRS.MoveFirst
%>
<TABLE BORDER=2>
<TR>
<TD><B>ID Number</B></TD>
<TD><B>First Name</B></TD>
<TD><B>Last Name</B></TD>
<TD><B>Month's Sales</B></TD>
</TR>
<TR>
<TD ALIGN="center"><%=
objRS.Fields("id") %></TD>
<TD ALIGN="left"><%= objRS.Fields
("first_name") %></TD>
<TD ALIGN="left"><%= objRS.Fields
("last_name") %></TD>
<TD ALIGN="right"><%=
objRS.Fields("sales") %></TD>
</TR>
</TABLE>
<%
End If
objRS.Close
End If

objRS.Open "sample", objDC, 0, 1
' Loop through recordset and display results
If Not objRS.EOF Then
objRS.MoveFirst
' the form below calls this file only this time with an id
in the QueryString
%>
<FORM ACTION="./db_pulldown.asp" METHOD="get">
<SELECT NAME="id">
<OPTION></OPTION>
<%
' Continue until we get to the end of the recordset.
Do While Not objRS.EOF
' For each record we create a option tag and set
it's value to the employee id
' The text we set to the employees first name
combined with a space and then their last name
%>
<OPTION VALUE="<%= objRS.Fields("id") %>"><%=
objRS.Fields("first_name") & " " & objRS.Fields("last_name") %
></OPTION>
<%
' Get next record
objRS.MoveNext
Loop
%>
</SELECT>
<INPUT type="submit" value="Submit">
</FORM>
<%
End If

' Close Data Access Objects and free DB variables
objRS.Close
Set objRS = Nothing
objDC.Close
Set objDC = Nothing
%>


  2002年1月8日  阅读 632 次  发送此页给朋友  来源:    版权争议  删除

相关文章:   近期热点:

上一篇: 何得知Recordset里的记录数
下一篇: ADO如何锁定RecordSet的记录呢?
返回上一层...
搜索:

(C)2004-2022 7i24.Com 保留所有权利