经典的ASP do循环只返回1个结果

时间:2015-08-22 16:41:31

标签: asp-classic

有人可以看看我的循环吗? SQL语句在SQL Management Studio中返回5个结果,但页面上只返回1个结果。我猜它是我的循环,但我不明白为什么。这可能是显而易见的事情。

function getpayments()  

dim sqlpay, rspay, oStr, paystat

sqlpay = (Returns 5 results) 
sqlexecute sqlpay, rspay
if not rspay.eof then
    do until rspay.eof
        paystat = rspay("Status")
        oStr = "<tr><td>" & sh(rspay("Date")) & "</td><td>" & sh(rspay("TypeName")) & "</td>"
            if (paystat = "Cheque Sent") or (paystat = "Transfer Made") or (paystat = "Cash Paid") or (paystat = "BACS Cleared") or (paystat = "Transfer Cleared") or (paystat = "BACS Sent") or (paystat = "Cash Cleared") or (paystat = "Cheque Cleared") then
                oStr = oStr & "<td><span class=""label label-success"">Complete</span></td>"
            elseif (paystat = "Committed") or (paystat = "On Hold") then
                oStr = oStr & "<td><span class=""label label-warning"">Pending</span></td>"
            else
                oStr = oStr & "<td><span class=""label label-danger"">Not Approved</span></td>"
            end if
        oStr = oStr & "<td>&pound;" & sh(rspay("Amount")) & "</td></tr>"
        rspay.MoveNext
    Loop
else
    oStr = "<tr><td>No payments found</td></tr>"
    rspay.close
end if
set rspay = nothing

getpayments = oStr

end function

1 个答案:

答案 0 :(得分:2)

我现在看到了。您可能正在获取5条记录,但每次迭代都会为oStr字符串分配一个值,覆盖之前的值。所以你可能只得到从这个函数返回的 last 记录。

oStr = "<tr><td>" & sh(rspay("Date"))...  ' This is overwriting any previous value

所以你真的没有在这里连接你的记录,因为它正在被每个新记录“重置”。只需将其更改为:

oStr = oStr & "<tr><td>" & sh(rspay("Date"))...