0
我尝试在Access中随机地查询结果集。订单访问ADODB记录集随机
我使用以下代码:
DIM TentamenQuestionID, TentamenQuestionResult, TentamenQuestionQuery, arrTentamenQuestion, arrTentamenQuestionIndex
Set TentamenQuestionResult = Server.CreateObject("ADODB.Recordset")
TentamenQuestionQuery = "SELECT TentamenQuestion.TentamenQuestionID, TentamenQuestion.TentamenQuestion, TentamenQuestion.TentamenQuestionSort " &_
"FROM TentamenQuestion " &_
"WHERE TentamenQuestion.TentamenID=" & TentamenID & " " &_
"ORDER BY Rnd(TentamenQuestion.TentamenQuestionID)"
TentamenQuestionResult.Open TentamenQuestionQuery, Connect, adOpenStatic, adLockReadOnly, adCmdText
If NOT TentamenQuestionResult.EOF then
arrTentamenQuestion = TentamenQuestionResult.GetRows()
End If
TentamenQuestionResult.Close
Set TentamenQuestionResult = Nothing
response.write(arrTentamenQuestion(0,0)) & "<br />"
response.write(arrTentamenQuestion(1,0)) & "<br />"
response.write(arrTentamenQuestion(2,0)) & "<br />"
response.write(arrTentamenQuestion(0,1)) & "<br />"
response.write(arrTentamenQuestion(1,1)) & "<br />"
response.write(arrTentamenQuestion(2,1)) & "<br />"
当我运行在Access查询,记录被随机选择,但是当我使用此代码和响应写入数组。数组每次排序相同,而不是随机排列。我怎样才能随机获得结果数组?
Randomize命令没有帮助,在select(ORDER BY)过程中应该发生排序。但我认为排序在检索到varient数组期间会被忽略。或者可以以某种方式缓存结果? – 2011-03-21 16:40:06