【问题标题】:Order access ADODB recordset randomly随机顺序访问 ADODB 记录集
【发布时间】:2011-03-22 17:01:53
【问题描述】:

我尝试在 Access 中随机订购带有查询的结果集。

我使用以下代码:

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 中运行查询时,记录是随机选择的,但是当我使用此代码并响应时写入数组。该数组每次排序都相同,而不是随机排序。如何随机获取结果数组?

【问题讨论】:

    标签: ms-access random adodb


    【解决方案1】:

    您可以在每次调用 Rnd() 函数之前尝试在 ASP 代码中的某处使用 Randomize 命令。

    否则,我很想知道排序是否在选择过程中发生,或者记录何时检索到变量数组中。您是否尝试过使用标准 ADO 语法 (MoveNext) 迭代记录以隔离问题?

    【讨论】:

    • Randomize 命令没有帮助,排序应该在选择(ORDER BY)期间进行。但我认为在将排序检索到变量数组中时,排序会以某种方式被忽略。或者结果可以以某种方式缓存?
    猜你喜欢
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多