Skip to main content
Participant
September 13, 2006
Question

Query using an array

  • September 13, 2006
  • 2 replies
  • 227 views
Hi, I am attempting to return figures based on a file being passed to my ASP page, this file is a csv, which I split and enter the details into an array. This works, I have checked, it is when I am attempting to query the database using the array I am having problems, I have shown the code I attempted, but with no joy.

The database connection is working I have tried and tested it.

Any help will be appreciated, thanks.

<%
for i = Lbound(DZArray) to UBound(DZArray)

if DZArray(i) <> "" then '... Error check insure that no vbNull value comes through from the array
Set rsSearch = con.execute("SELECT * FROM MYEPopByNewAgeGroups WHERE MYEPopByNewAgeGroups.DataZone = '" & DZArray(i) & "'")

IF not rs.EOF then '... Error Check insure that a value is returned from the select statement
while not rsSearch.eof
%>
<tr>
<td><%= rsSearch("DataZone")%></td>
<td><%= rsSearch("Under 5")%></td>
<td><%= rsSearch("5-15")%></td>
<td><%= rsSearch("16-24")%></td>
</tr>
<%
rsSearch.movenext
wend
end if
%>
This topic has been closed for replies.

2 replies

Angell EYE
Inspiring
September 13, 2006
Looks like you might just be missing the Next that runs the loop...??
Angell EYE
Inspiring
September 13, 2006
Not sure exactly what you're trying to accomplish here but here's an example of something similar I've done. This code loops through the array of submitted form check boxes and adds each one to my shopping cart.

<%
checkedProducts = Request.Form("ATCCheck")
checkedProductsSplit = Split(checkedProducts,",")
for i = LBound(checkedProductsSplit) to UBound(checkedProductsSplit)
%>

<%
Dim rsAddedItems
Dim rsAddedItems_cmd
Dim rsAddedItems_numRows

Set rsAddedItems_cmd = Server.CreateObject ("ADODB.Command")
rsAddedItems_cmd.ActiveConnection = MM_connKennysMDIData_STRING
rsAddedItems_cmd.CommandText = "SELECT kennysInventoryID, productDescription1, productID, productName, unitPrice, weight FROM products WHERE productID = "&checkedProductsSplit(i)&""
rsAddedItems_cmd.Prepared = true

Set rsAddedItems = rsAddedItems_cmd.Execute
rsAddedItems_numRows = 0
%>

<%
'Add item to shopping cart
%>

<%
Next
%>

<%
rsAddedItems.Close()
Set rsAddedItems = Nothing
%>