Array Problem

1. Avril Guest

## Array Problem

I have an array which stores comma delimited strings which are passed in from a list box on a form. I then need to run a SQL statement for each individual entry in the array. The statement executes correctly for the first iteration of the loop but after that 0 is returned each time.<BR>Here is the code<BR><BR>county = Request.Form("County")<BR>A = Split(county, ",")<BR>&#039;A is the array<BR><BR>for x = 0 to UBound(A)<BR> Set RS1 = Server.CreateObject("ADODB.Recordset")<BR> sql1 = "SELECT count (ID) FROM [666] where countycategory like &#039;%"& A(x)& "%&#039;"<BR> RS1.Open sql1, conn<BR> RSCount1 = RS1.Fields.Item(0).Value<BR> Response.write RSCount1<BR> RS1.Close<BR> Response.write SQL1<BR> Set RS1 = Nothing<BR>Next<BR><BR>This is the output I am getting<BR><BR>cork<BR>SELECT count (ID) FROM [666] where countycategory like &#039;%cork%&#039;<BR>9<BR><BR>dublin<BR>SELECT count (ID) FROM [666] where countycategory like &#039;% dublin%&#039;<BR>0<BR><BR>The output value for the second SQL stmt should not be 0<BR><BR>Any suggestions!!!!!!!!<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
614

## RE: Array Problem

just a guess but is the a &#060;SPACE&#062; in &#039;% dublin%&#039; <BR> and should it be there?

3. Senior Member
Join Date
Dec 1969
Posts
1,944

## RE: Array Problem

The problem is not with the array, but the contents of the array which u dumped from the listbox.see there are any spaces etc before or after the commas.(before u split it).That could be the reason.(u can also Check for the length of the words, to make sure)<BR><BR>Lastly,don&#039;t loop through creating the recordeset everytime.<BR>start the loop after the recordset creation.

4. Avril Guest

## RE: Array Problem

That actually just occurred to me too, but I thought that the % sign would take care of that. I am just testing it right now. <BR>Thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•