主题:用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]
[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]