ASP/GetRows&数数 [英] ASP / GetRows & Count

查看:98
本文介绍了ASP/GetRows&数数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

To enhance performance and resources, I've just started to use getRows() on a few of my scripts. I have just come across an issue, which I'd like to ask about.

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

I was doing this to get the recordset and to get the count:

If NOT rs.EOF Then
    arrResultSet = rs.GetRows()
    arrRowCount = UBound(arrResultSet,2)
End If

但是后来我意识到我丢失了一条记录,所以我在计数中加了1:

But then I realised I was missing a record so I added 1 to my count:

If NOT rs.EOF Then
        arrResultSet = rs.GetRows()
        arrRowCount = UBound(arrResultSet,2) + 1
End If

但是现在当我稍后尝试访问数据数组时,在脚本中出现错误,这纯粹是因为我要加一:

But now I get an error later in my script when I try accessing the data array which is purely down to adding one to my count:

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(...)'

任何帮助都将不胜感激.

Any help greatly appreciated.

推荐答案

您的For从0的索引移到arrRowCount的索引.

Your For is going from the index of 0 to the index of the arrRowCount.

例如,如果您有三个记录,那么您将从0转到3,即4,对吗? IIRC,我们曾经这样做:For iCounter = 0 to arrRowCount - 1

So, for example, if you have three records, you are going from 0 to 3, which is 4, right? IIRC, we used to do this: For iCounter = 0 to arrRowCount - 1

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

Edit: Perhaps this example will help you. This web page details why using GetRows yields a performance improvement, so I think you're on the right track. I have included the entire code sample, but you are interested in the part at the end. It has less code, and fewer variables, than you are using. It looks cleaner, simpler.

' 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

这篇关于ASP/GetRows&数数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆