gpt4 book ai didi

asp-classic - ASP/GetRows & 计数

转载 作者:行者123 更新时间:2023-12-01 23:18:51 25 4
gpt4 key购买 nike

为了提高性能和资源,我刚刚开始在我的一些脚本中使用 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(...)'

非常感谢任何帮助。

最佳答案

您的 For 从索引 0 到 arrRowCount 的索引。

因此,例如,如果您有三个记录,则从 0 到 3,也就是 4,对吗? IIRC,我们曾经这样做:For iCounter = 0 to arrRowCount - 1

编辑:也许这个例子会对你有所帮助。这web page详细说明了为什么使用 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

关于asp-classic - ASP/GetRows & 计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8916384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com