回 帖 发 新 帖 刷新版面

主题:用ASP在access下随机选记录

最近我在做毕业设计——在线考试系统,用ACCESS做数据库,需要在数据库中随机抽取试题,找到一些代码和大家起分享。   
[size=4][color=FF0000]access下随机选记录[/color]:[/size]
<% 
on error resume next
             
dim varray
varray=request.form("selNum")
dim count()
redim count(varray)
dim stidString
sql="select * from tbl_stk where bookid='"&bookid&"'"
set rs = server.createobject("adodb.recordset")
rs.open sql, conn, 3, 3
iMin = 1
iMaxif rs.bof and rs.eof then 
response.redirect("../success.asp?messageid=reg010")
end if
sub rand(i)
Randomize
'count(i) = Int(((imax- iMin + 1) * Rnd) + imin)
count(i) = Int((imax * Rnd) + imin)
for j=1 to i-1 
if count(i)=count(j) then
rand i
end if
next 
end sub
            
sub randit()
for i=0 to varray
rand i
next
end sub
call randit()
            
'check exist
for j=0 to ubound(count)
set rsCheck=conn.execute("select * from tbl_stk where bookid='"&bookid&"' and stid='"&count(j)&"'")
if rsCheck.bof and rsCheck.eof then 
    'count(j)=Int(((imax- iMin+1) * Rnd) + imin)
    count(j)= Int((imax * Rnd) + imin)
    end if
        rsCheck.close
        set rsCheck=nothing
        next
        'check end
        %>
[em15][em15][em2]

回复列表 (共2个回复)

沙发

我毕业设计也做的这个题目,不过数据库要用SQL的,随机存取方法跟你的不太一样。
有机会交流下,我在忙写论文呢!
老兄啥时候答辩呢?

板凳

我什么都不懂,但是想学习编程,谁可以教我啊.或者去那里学习啊

我来回复

您尚未登录,请登录后再回复。点此登录或注册