悬赏:ASP题库程序,随机抽出 5 题?

dy630 2002-05-16 08:32:46
用Access 数据库
3Q!
...全文
11 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
wuya0531 2002-05-16
联系我,发给你,刚好实习就做这个,sql
qq:6623560
回复
BrightEye 2002-05-16
随机取出n条记录的方法:
SELECT TOP n * FROM table_name ORDER BY NEWID()

top n,n就是要取出的记录数

回复
wangfei2428 2002-05-16
http://www.csdn.net/expert/topic/723/723789.xml?temp=.3942224
回复
wangfei2428 2002-05-16
sql环境下用
selec top N * from someTable where 题目类型='单选题' order by NewID()

access环境下随机读取单选题10条
//读取符合单选题的所有记录
<!--#include virtual="/adovbs.inc"-->
count=10
strConnection="driver={Microsoft Access Driver (*.mdb)};dbq=" & server.mappath("/testdb.mdb")
strSQL = "SELECT id FROM tblQuestions where 题目类型='单选题'"

set objConn = Server.CreateObject("ADODB.Connection")
Set objRst = Server.CreateObject("ADODB.Recordset")
objConn.Open strConnection
set objRst.ActiveConnection = objConn
objRst.LockType = adLockOptimistic
objRst.CursorType = adOpenKeySet
objRst.Open strSQL

//计算记录的个数
objRst.MoveLast
cnt = objRst.RecordCount
cnt1 = cnt
rndMax = cnt

//比较要输出的记录个数10与所有记录个数的大小
If CInt(count) < cnt Then
cnt1 = CInt(count)
End If

//随机抽出10条记录的id号,并用","连接
str = ","
str1 = ","

Do Until cnt1 = 0
Randomize
RndNumber = Int(Rnd * rndMax)

If (InStr(1, str1, "," & RndNumber & "," ) = 0) Then
str1 = str1 & RndNumber & ","
cnt1 = cnt1 - 1
objRst.MoveFirst
objRst.Move RndNumber
str = str & objRst("id") & ","
End If
Loop
objRst.Close
Set objRst = Nothing

//读出记录
sql = "SELECT * FROM tblQuestions WHERE (((InStr(1,'" & str & "',(',' & [id] & ',')))<>0)) "
Set objRst = Server.CreateObject("ADODB.Recordset")
set objRst.ActiveConnection = objConn
objRst.LockType = adLockOptimistic
objRst.CursorType = adOpenKeySet
objRst.Open sql
%>
...显示记录
<%
objRst.Close
Set objRst = Nothing

objConn.Close
Set objConn = Nothing
%>
其他依次类推。
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2002-05-16 08:32
社区公告
暂无公告