ArrayList and FilterRow

  • Thread starter Thread starter TigerMan
  • Start date Start date
T

TigerMan

Hi,

I have an interesting problem. With the code below, the loop takes ages to
run:

For intA = 0 To aryJobs.Count - 1
Dim strJobx As String = aryJobs(intA).ToString
strJobx = "JobNumb = '" & strJobx & "'"
adsWork.Tables(0).DefaultView.RowFilter = strJobx
......
Next intA
......

If I change it to this, it is super fast:
For intA = 0 To aryJobs.Count - 1
Dim strJobx As String strJobx = "JobNumb = '00001"
adsWork.Tables(0).DefaultView.RowFilter = strJobx
......
Next intA
.......

Yet the first item in the ArrayList(0) is "00001" so why is it way slower
when I try to pass an ArrayList rather than the number 00001 as seen above?
I have also tried an array of string with the same slow result. I have left
the code out where the ... are as the perfomance problem is in the above
code. Is this problem because setting the number direct is like a constant
where getting it from an arraylist is really slow?

The reason I have to do this is because i am upgrading data where there is a
'jobnumb' field in an access table but there could be several records for it
under 1 job number, however the source is flat file and one job could have a
different extension (say one part might be 00001-02A and another part
00001-02 and so on and many variations on that) so I create a datatable that
I add temp fields too so I can get the job number to be the same so I can
filter the records and I built an arraylist of unique jobnumbs then I can
import the records to a new relational setup so there is only 1 jobnumb with
relations to other tables. I tied making a temp table but no difference.

TIA
 
Hi,

I have an interesting problem. With the code below, the loop takes ages to
run:

For intA = 0 To aryJobs.Count - 1
Dim strJobx As String = aryJobs(intA).ToString
strJobx = "JobNumb = '" & strJobx & "'"
adsWork.Tables(0).DefaultView.RowFilter = strJobx
.....
Next intA
.....

If I change it to this, it is super fast:
For intA = 0 To aryJobs.Count - 1
Dim strJobx As String strJobx = "JobNumb = '00001"
adsWork.Tables(0).DefaultView.RowFilter = strJobx
.....
Next intA
......

Yet the first item in the ArrayList(0) is "00001" so why is it way slower
when I try to pass an ArrayList rather than the number 00001 as seen above?
I have also tried an array of string with the same slow result. I have left
the code out where the ... are as the perfomance problem is in the above
code. Is this problem because setting the number direct is like a constant
where getting it from an arraylist is really slow?

The reason I have to do this is because i am upgrading data where there is a
'jobnumb' field in an access table but there could be several records for it
under 1 job number, however the source is flat file and one job could have a
different extension (say one part might be 00001-02A and another part
00001-02 and so on and many variations on that) so I create a datatable that
I add temp fields too so I can get the job number to be the same so I can
filter the records and I built an arraylist of unique jobnumbs then I can
import the records to a new relational setup so there is only 1 jobnumb with
relations to other tables. I tied making a temp table but no difference.

TIA
Well, first thing I see is that you are performing two operations in the first
example instead of one. Second, of course the second example is faster than the
first, because you are simply assigning the same value to the same variable over
and over again.

IMHO the first example should be ( in C# ):

foreach(string s in aryJobs)
{
string strJbox = "JobNum = " + s + "'";
// or string strJbox = string.format("JobNumb = '{0}'", s);
}

The first example you gave will never be as fast as the second in VB or any
other language.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
Thanks for the tip Otis

Otis Mukinfus said:
Well, first thing I see is that you are performing two operations in the
first
example instead of one. Second, of course the second example is faster
than the
first, because you are simply assigning the same value to the same
variable over
and over again.

IMHO the first example should be ( in C# ):

foreach(string s in aryJobs)
{
string strJbox = "JobNum = " + s + "'";
// or string strJbox = string.format("JobNumb = '{0}'", s);
}

The first example you gave will never be as fast as the second in VB or
any
other language.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
Tigerman,

I don't know why it is slow, but both the codes are whithout sense.
For intA = 0 To aryJobs.Count - 1
Dim strJobx As String = aryJobs(intA).ToString
strJobx = "JobNumb = '" & strJobx & "'"
Above you set a string in strJobx, than you use that to fill that strJobx
again, a little bit confusing
adsWork.Tables(0).DefaultView.RowFilter = strJobx
The result will be that only the last item from ArJobs will be in the
rowfilter
.....
Next intA
.....

If I change it to this, it is super fast:
For intA = 0 To aryJobs.Count - 1
Dim strJobx As String strJobx = "JobNumb = '00001"
In my idea does this not compile, so I don't believe that you show us tested
samples.

Even when we splits it is the result the same as above only one time will
the rowfilter be build.
adsWork.Tables(0).DefaultView.RowFilter = strJobx
.....
Next intA
......
Cor
 
Hi Cor,


Cor Ligthert said:
Tigerman,

I don't know why it is slow, but both the codes are whithout sense.

Above you set a string in strJobx, than you use that to fill that strJobx
again, a little bit confusing

Sorry I did have the wrong code in there. I did have the correct code
before and somehow messed that up.

The correct code should have been:

For intA = 0 To aryJobs.Count - 1
Dim strJobx As String = aryJobs(intA).ToString
adsWork.Tables(0).DefaultView.RowFilter = "JobNumb = '" & strJobx &
"'"
.....
Next intA
.....

Anyway I solved it by using DataTable.Select:

Dim dr As DataRow()
For intA = 0 To aryJobs.Count - 1
dr = adsWork.Tables(0).Select(aryJobs(intA))
.....
Next intA
....
 
Back
Top