ASP+Access随机读取数据库记录的方法

两种方法,都利用了随机数!

方法一: 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!--#include file="qiconn.asp"-->

<%

Randomize(timer())

bgsql = "select top 5 fuid,id,lcolor,name from lei order by rnd(-(id + " & Int((10000 * Rnd) + 1) & "))"

set bgrs=server.CreateObject("adodb.recordset")

bgrs.open bgsql,conn,1,1

 if bgrs.eof and bgrs.eof then

  response.write ""

 else

  do until bgrs.eof

  

   response.write bgrs("name") & "<br>"

  bgrs.movenext

  loop

 end if

bgrs.closd

set bgrs=nothing

%>

</body>

</html>

方法二、 

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<!--#include file="qiconn.asp"-->

<%

dim rndnum

 Randomize  

 Do While Len(rndnum)<2

 num1=CStr(Chr((57-48)*rnd+48))

 rndnum=rndnum&num1

 loop

 Randomize 

bgsql = "select * from lei where id>"& rndnum &" order by rnd(id) desc"

set bgrs=server.CreateObject("adodb.recordset")

bgrs.open bgsql,conn,1,1

 if bgrs.eof and bgrs.eof then

  response.write ""

 else

  do until bgrs.eof

  

   response.write bgrs("name") & "<br>"

  bgrs.movenext

  loop

 end if

bgrs.closd

set bgrs=nothing

%>

</body>

</html>

参与评论

  • 刘易俊

    看好诺豆!支持你!

    14年前 (2010-01-01)
    回复
    回复刘易俊
  • 刘易俊

    技术是寂寞的!
    新年好啊!

    nuodou 于 2010-1-1 23:19:21 回复

    诺豆回归,再寂寞也会走下去

    14年前 (2010-01-01)
    回复
    回复刘易俊
  • 最好

    很有用啊~~学习了!欢迎回访哈!

    nuodou 于 2010-1-1 23:21:02 回复

    这可是纯顶啊呵呵

    14年前 (2009-12-31)
    回复
    回复最好
  • 老七

    第一次来。。呵呵 欢迎回访。。

    nuodou 于 2010-1-1 23:21:24 回复

    也是第一次回复你呵呵

    14年前 (2009-12-31)
    回复
    回复老七
  • 土狼妹妹

    数字一看就头大,不过必须学的

    nuodou 于 2009-12-23 11:52:01 回复

    知道一点好办事

    14年前 (2009-12-22)
    回复
    回复土狼妹妹
  • 园子

    专业的文章
    学习学习。

    14年前 (2009-12-18)
    回复
    回复园子
  • 张楠

    呵呵,ASP+AC最主要是简单

    14年前 (2009-12-17)
    回复
    回复张楠
  • 疾风

    代码如诗啊 呵呵~·

    nuodou 于 2009-12-17 12:11:06 回复

    诗意!!

    14年前 (2009-12-17)
    回复
    回复疾风
  • daniel

    小型数据库对一般的小网站来说,还是很经济实惠的。

    nuodou 于 2009-12-16 21:48:53 回复

    特别是一般的企业网站

    14年前 (2009-12-16)
    回复
    回复daniel
  • 风云春秋博客

    ASP+Access只适合小网站和企业网站 到了论坛就要换数据库喽

    nuodou 于 2009-12-16 12:51:10 回复

    是啊,我深有体会呵呵!但ASP+Acc还是很有市场的

    14年前 (2009-12-16)
    回复