Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp classic ASP/GetRows&;计数_Asp Classic - Fatal编程技术网

Asp classic ASP/GetRows&;计数

Asp classic ASP/GetRows&;计数,asp-classic,Asp Classic,为了提高性能和资源,我刚刚开始在一些脚本上使用getRows()。我刚刚遇到一个问题,我想问一下 我这样做是为了获取记录集和计数: If NOT rs.EOF Then arrResultSet = rs.GetRows() arrRowCount = UBound(arrResultSet,2) End If 但后来我意识到我丢失了一张唱片,所以我在我的计数中加了1: If NOT rs.EOF Then arrResultSet = rs.GetRows()

为了提高性能和资源,我刚刚开始在一些脚本上使用getRows()。我刚刚遇到一个问题,我想问一下

我这样做是为了获取记录集和计数:

If NOT rs.EOF Then
    arrResultSet = rs.GetRows()
    arrRowCount = UBound(arrResultSet,2)
End If
但后来我意识到我丢失了一张唱片,所以我在我的计数中加了1:

If NOT rs.EOF Then
        arrResultSet = rs.GetRows()
        arrRowCount = UBound(arrResultSet,2) + 1
End If
For iCounter = 0 to arrRowCount
    ...some code...
    If LCase(Trim(peopleWord)) = LCase(Trim(arrResultSet(1,iCounter))) Then
    ...some code...
Next

Microsoft VBScript runtime error '800a0009'
Subscript out of range: 'lcase(...)'
但现在,当我稍后尝试访问数据数组时,我的脚本中出现了一个错误,这纯粹是因为在我的计数中添加了一个:

If NOT rs.EOF Then
        arrResultSet = rs.GetRows()
        arrRowCount = UBound(arrResultSet,2) + 1
End If
For iCounter = 0 to arrRowCount
    ...some code...
    If LCase(Trim(peopleWord)) = LCase(Trim(arrResultSet(1,iCounter))) Then
    ...some code...
Next

Microsoft VBScript runtime error '800a0009'
Subscript out of range: 'lcase(...)'

非常感谢您的帮助。

您的
For
的索引将从0变为
arrowcount
的索引

例如,如果你有三条记录,你从0到3,也就是4,对吗?IIRC,我们曾经这样做:
对于iCounter=0到arrRowCount-1

编辑:也许这个例子会对您有所帮助。这详细说明了为什么使用
GetRows
可以提高性能,因此我认为您的做法是正确的。我已经包括了整个代码示例,但是您对最后的部分感兴趣。它的代码和变量比您使用的要少。它看起来更干净、更简单

' Establish the connection object
strConn = "[connection string goes here]"
set dbConn = Server.CreateObject("ADO.Connection")
dbConn.Open strConn

' Establish the recordset object
set rsCustomers = Server.CreateObject("ADO.Recordset")
set rsCustomers.ActiveConnection = dbConn

' Load the recordset object based on supplied query
strSQL = "SELECT RecID, FirstName, LastName FROM Customers"
rsCustomers.Open strSQL

' Push the results into a two-dimensional array
dataArray = rsCustomers.GetRows()

' Cleanup the objects. We do it here instead of at the end because the data
' has already been placed into an array. This is an advantage in that we can release
' memory sooner.
rsCustomers.Close
set rsCustomers = nothing

dbConn.Close
set dbConn = nothing

' Retrieve the records performing business logic where necessary
jMax = ubound(dataArray, 2)
for j = 0 to jMax

    'Additional business logic here

next

这成功了,谢谢@DOK。为了确认,我保留了UBound(arresultset,2)+1,但在循环时使用iCounter=0来arrRowCount-1?是的,但这看起来有点尴尬,不是吗?看看我的编辑。事实上,很抱歉让你感到痛苦,我尊重你的帮助,但我不理解这个例子。它对UBound计数没有+1,对于j=0对jMax没有-1希望你不介意我问更多,我的代码可以工作,但我完全理解正确的方法:)我可以听到齿轮磨的声音。基本上,你可以坚持你知道有效的+1和-1方法。或者,您可以注释掉该代码,尝试另一种更简单的方法,并逐步执行,直到对您有意义为止。你也可以试着读那篇文章。在我看来,你的基本斗争是从索引为0开始循环,然后将其与计数混合,而计数不是从零开始的。祝你好运