I'm trying to fix an ASP Classic app and when I try to create an array from a Recordset Object. However I Can't get it to work correctly.
This code gives me a single record (the last one), but as far as I can see it is correct:
Dim Products
Dim Products_cmd
Dim Products_numRows
Set Products_cmd = Server.CreateObject ("ADODB.Command")
Products_cmd.ActiveConnection = Conn
Products_cmd.CommandText = "SELECT prod_id, prod_description FROM dbo.products ORDER BY prod_description ASC"
Products_cmd.Prepared = true
Set Products = Products_cmd.Execute
Products_numRows = 0
Dim arrProducts()
arrProducts = Products.GetRows()
Using this code gives me an "Subscript out of range: 'UBound'
Dim Products
Dim Products_cmd
Dim Products_numRows
Set Products_cmd = Server.CreateObject ("ADODB.Command")
Products_cmd.ActiveConnection = Conn
Products_cmd.CommandText = "SELECT prod_id, prod_description FROM dbo.products ORDER BY prod_description ASC"
Products_cmd.Prepared = true
Set Products = Products_cmd.Execute
Products_numRows = 0
Dim arrProducts()
Dim counter
For counter = 0 to Products.RecordCount - 1
ReDim Preserve arrProducts(counter,2)
arrProducts(counter,0) = Products.Fields.Item("prod_id").Value
arrProducts(counter,1) = Products.Fields.Item("prod_description").Value
Products.MoveNext
Next
Response.Write(Str(UBound(arrProducts)))
Any ideas would be GREATLY appreciated...
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…