Ouch, it looks like right now your doing a lot of extra loops. I mean even if you only have ten records in your first recordset, thats 11 connections objects, 11 recordset objects (that you don't need), 11 calls to the database...wow.
To answer your previous post, your getting 0 back for the first array because your storing a two-dimensional array that's UBounds are 0,n. Since you didn't tell the UBound function which dimension you wanted the upper bound on (in your print statement) it went and got the upper bound for the first dimension. If you change your statement to:
Code:
RESPONSE.WRITE("manufacturerArray " & UBOUND(Application("manufacturerArray")[highlight],2[/highlight]) & "<BR>")
you should be set.
I know it wasn't originally your question, but I think we can find a better chain of logic to get the results you need.
First of all, if you are going to be receiving a recordset back from a ConnectionObject.Execute you do no need to Server.CreateObject that Recordset ahead of time. The connection objectis going to be creating it's own recordset internally then replacing whatever your recordset variable is pointing at (in this case a brand new recordset) with the populated one.
Also, I'm not sure why you have the loop in the middle at all?
A simpler solution would be a single sql statement that returns both the manufacturer andthe product count all at once, cutting down on that count + 1 calls to the database:
Code:
Query = "SELECT DISTINCT manufacturerNameSTR, COUNT(productIdINT) " & _
"FROM manufacturers INNER JOIN products ON manufacturers.manufacturerNameInt = products.manufacturerNameINT " & _
"WHERE (manufacturerNameSTR IS NOT NULL) " &_
"AND (manufacturerNameSTR <> 'Gift Certificate') " & _
"GROUP BY manufacturerNameSTR"
Now we would receive a recordset that gives us the manufacturer name and product count (personally I would also order it by manufacturer name so I would hav a pretty alphabetical list, but thats just me).
Now if you still wanted this to be in two arrays you could simply call GetRows twice, which will still be amazingly cheaper then the count + 1 connections, etc
Code:
Query = "SELECT DISTINCT manufacturerNameSTR, COUNT(productIdINT) as manProductCount" & _
"FROM manufacturers INNER JOIN products ON manufacturers.manufacturerNameInt = products.manufacturerNameINT " & _
"WHERE (manufacturerNameSTR IS NOT NULL) " &_
"AND (manufacturerNameSTR <> 'Gift Certificate') " & _
"GROUP BY manufacturerNameSTR"
Dim db_conn, rs_manufs
'Create and open the connection
Set db_conn = Server.Createobject("ADODB.Connection")
db_conn.Open dbLocation
'Execute the query and grab the returned recordset
Set rs_manufs = db_conn.Execute(Query)
'store this as two arrays in Application variables
Application("ManufacturerName") = rs_manufs.GetRows(-1,1,"manufacturerNameINT")
Application("ManufacturerProdCount") = rs_manufs.GetRows(-1,1,"manProductCount")
Set rs_manufs = Nothing
db_conn.Close
Set db_conn = Nothing
If you don't like ave 0, n arrays and just want a single dimension array it would be fairly easy to assign those two arrays to temporary variable and create a couple new arrays base on their UBounds, here is an example function:
Code:
'accepts an array to flatten and a numeric field to flatten (first index)
Function FlattenRSArray(arrOriginal,fieldToFlatten)
Dim arr_new, ctr
ReDim arr_new(UBound(arrOriginal,2)
For ctr = 0 to UBound(arr_new)
arr_new(ctr) = arrOriginal(fieldToFlatten,ctr)
Next
FlattenRSArray = arr_new
End Function
So if we were to add that to the code I had above, we would now have:
Code:
Query = "SELECT DISTINCT manufacturerNameSTR, COUNT(productIdINT) as manProductCount" & _
"FROM manufacturers INNER JOIN products ON manufacturers.manufacturerNameInt = products.manufacturerNameINT " & _
"WHERE (manufacturerNameSTR IS NOT NULL) " &_
"AND (manufacturerNameSTR <> 'Gift Certificate') " & _
"GROUP BY manufacturerNameSTR"
Dim db_conn, rs_manufs
'Create and open the connection
Set db_conn = Server.Createobject("ADODB.Connection")
db_conn.Open dbLocation
'Execute the query and grab the returned recordset
Set rs_manufs = db_conn.Execute(Query)
'get the data into an array and break it into two separate 1-dimensional arrays
Dim arr_temp
Set arr_temp = rs_manufs.GetRows(-1,1,"manufacturerNameINT,ManufacturerProdCount")
Set rs_manufs = Nothing
db_conn.Close
Set db_conn = Nothing
'store data as two arrays in Application variables
Application("ManufacturerName") = FlattenRSArray(arr_temp,0)
Application("ManufacturerProdCount") = FlattenRSArray(arr_temp,1)
Hopefully that will help increase your efficiency by at least a single order of magnitude, possibly more depending on how many records there were in the manufacturers table.
-T
01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website: