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