在记录集上执行 while 循环继续运行,而总记录数更少

Nic*_*las 0 sql-server loops recordset asp-classic

IO 在我的 asp 经典页面中遇到了一个非常奇怪的问题。我正在为员工制定休假时间表。当我测试它时,它似乎工作正常。虽然有另一种选择,我可以来回走一周,当我回到 3 周时,循环一直在单张唱片上循环。

所以我想通过在 SQL 执行后对记录集进行计数来检查问题出在哪里。

但出于某种原因,do while 循环一直在循环。我在 do while 中做了一个打印计数,看看它找到了多少条记录,现在它已经在 508 000 上了!

所以在我的 t-sql 服务器(2012)中,我做了完全相同的查询,这里它只产生了 953 条记录......

所以很明显,循环中出现了问题。

这是我正在使用的代码:

strSQL = "SELECT * FROM [qrySnipperKalender_B] WHERE [snipperdag] >= "& szStart &" AND [snipperdag]<= "& szEnd &" ORDER BY [FunctieGroep], [Relatienaam], [Datum] ASC"


    response.write(strSQL & "<br> <br>")

    set rst=con_sql.execute(strSQL)
    CountCheck = 0


    Do until rst.EOF or rst.BOF
        response.write("Count is: " & CountCheck & "<br>")

        CountCheck = CountCheck + 1
    Loop

    response.write("RST count      :" & CountCheck)
    response.end
Run Code Online (Sandbox Code Playgroud)

response.end 和 response.write RST 计数永远不会被命中,它只是不断循环使页面非常慢。

response.write SQL 的结果是: SELECT * FROM [qrySnipperKalender_B] WHERE [snipperdag] >= 15281 AND [snipperdag]<= 15355 ORDER BY [FunctieGroep], [Relatienaam], [Datum] ASC

当我在 SQL 服务器中运行此查询时,它会生成 953 条记录(应该如此)。

所以问题是,为什么这个循环被破坏/让它继续运行?

我已经尝试使用 rst.BOF 修改循环(首先我只有 EOF),但这没有任何效果。我还尝试在循环中使用 IF 条件,如果它遇到 EOF 则退出循环,但这也不起作用。

Ale*_* K. 5

您忘记rst.MoveNext在循环中导航到下一条记录

Do while not rst.EOF 
    CountCheck = CountCheck + 1
    response.write("Count is: " & CountCheck & "<br>")
    rst.MoveNext
Loop
Run Code Online (Sandbox Code Playgroud)