filling arraylist with arraylists in loop problem

D

drdave

Hi All,

I'm filling an arraylist with other arraylists within a loop and within
the first iteration and addition all is fine.. however when I clear my
value holding temporary array I lose the values already in the output
array..

the code..

'******** LOOP OVER THE PROVINCE ID VALUES ********************

For Each y in ProvArrList
'there are 14 provinces


' '**** OUTPUT THE QUERY *****************************
'there are 10 years

For Each x in YearArrList

n = (x + 1)
n = "12/31/" & n
x = "12/31/" & x
Dim s As String = ""
' Get the years and jurisdictions

Dim filterstatement As New StringBuilder
filterstatement.append ("effective_date >
#").Append(x).Append("#").Append("And effective_date <
#").Append(n).Append("#").Append("AND prov_prov_id = ").Append(y.Key)

Dim Filter As String = (filterstatement.ToString())
Response.Write (Filter)


DBDataView.RowFilter = Filter
'Add the values into my temporary holding arraylist

If DbDataView.Count < 1

arrTemplist.Add ("&nbsp;")


Else

For Each drv In DBDataView

s &= Format(drv("effective_date"),"D")& ControlChars.NewLine &
formatCurrency(drv("minimum_wage_amount")) &
drv("mwv_minimum_wage_variation_id") & "p= " & drv("prov_prov_id")
arrTemplist.Add (s)

Next

End If

' End of Years


Next
arrHolder.Add (arrTemplist)
arrTemplist.Clear () <!----------------------------------- CLEARS
arrHolder existing values also

Next


Hopefully this is clear enough but here is the debug output..

in the first iteration I get my values and all is good:

+ arrTemplist {Length=10}
- arrHolder {Length=1}
+ (0) {Length=10}

After I run arrtemplist.Clear it clears my arrHolder arrtemplist

arrTemplist {Length=0}
- arrHolder {Length=1}
(0) {Length=0}

Why does this happen?? How can I empty my temp list and keep my good
values..

thx.
 
P

Peter Rilling

Rather than clearing the temp list, you should create a new instance. You
are adding the temp list to your final list and therefore any future
operations will affect all instances. You need a new instance to work on
for each loop.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top