ASP / GetRows & Count

前端 未结 1 1236
我在风中等你
我在风中等你 2021-01-20 14:17

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 w

相关标签:
1条回答
  • 2021-01-20 14:22

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

    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

    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
    
    0 讨论(0)
提交回复
热议问题