ASP随机读取数据库中几条数据代码
分类:程序开发 Tags: asp 数据库 评论:0 浏览:5546 最近更新时间:2008/5/22 23:42:34
方法一:
Randomize(Timer())
SQL = "SELECT TOP 100 ID FROM table1 ORDER BY Rnd(-(ID + " & Int((10000 * Rnd) + 1) & "))"
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Open SQL,Conn,1,1
If Not RS.EOF Then
RS.MoveFirst
For I = 1 To RS.RecordCount
Response.Write RS(0) & "<br>"
RS.MoveNext
Next
End If
RS.Close
Set RS = Nothing
方法二:
’--- 连接数据库
Dim Db,Conn
Db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("date/shop.mdb")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open Db
’--- ASP&Access随机读取某段数据
Randomize
’--- 得到总得记录数
dim countid
countid=conn.execute("select count(id) from product")(0)
’--- 获得随机数
dim rndid
rndid=int(rnd*countid)
rndid=rndid+5
dim rs,sql
’--- SQL查询
sql="select top 5 id,name from product where id in (select top "&rndid&" id from product) order by id desc"
’Response.Write(sql)
set rs=conn.execute(sql)
if not rs.eof then
do while not rs.eof
response.Write(rs(0)&" - <a href=""list.asp?id="&rs(0)&""" target=""_blank"">"&rs(1)&"</a><BR />")
rs.movenext
loop
end if
set rs=nothing
Randomize(Timer())
SQL = "SELECT TOP 100 ID FROM table1 ORDER BY Rnd(-(ID + " & Int((10000 * Rnd) + 1) & "))"
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Open SQL,Conn,1,1
If Not RS.EOF Then
RS.MoveFirst
For I = 1 To RS.RecordCount
Response.Write RS(0) & "<br>"
RS.MoveNext
Next
End If
RS.Close
Set RS = Nothing
方法二:
’--- 连接数据库
Dim Db,Conn
Db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("date/shop.mdb")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.open Db
’--- ASP&Access随机读取某段数据
Randomize
’--- 得到总得记录数
dim countid
countid=conn.execute("select count(id) from product")(0)
’--- 获得随机数
dim rndid
rndid=int(rnd*countid)
rndid=rndid+5
dim rs,sql
’--- SQL查询
sql="select top 5 id,name from product where id in (select top "&rndid&" id from product) order by id desc"
’Response.Write(sql)
set rs=conn.execute(sql)
if not rs.eof then
do while not rs.eof
response.Write(rs(0)&" - <a href=""list.asp?id="&rs(0)&""" target=""_blank"">"&rs(1)&"</a><BR />")
rs.movenext
loop
end if
set rs=nothing
本文地址:/342/
-
• ASP在后一页刷新前一页代码
• ASP网页过滤HTML代码的多种方法
• 把Access 2010 .accdb文件格式转换为Access 2003 .mdb操作方法
• windows 2003通过squid搭建cdn节点加速服务
• 网页加密攻略:使用ASP程序密码锁
• ASP获取文件所在文件夹名称、复制文件、创建、删除文件夹代码
• js点击复制代码
• ASP多个关键词搜索代码,关键词以+号或空格隔开
• ASP将汉字转为拼音代码
• ASP提交Post数据到远程网站的方法