Why is this code so slow?

tb303

Supreme Member
Joined
Dec 18, 2011
Messages
1,237
Reaction score
909
Code:
Dim num As Integer = DataSet1.Tables(0).Rows.Count - 1
Dim no As String = "No"
For n = num To 0 Step -1
     DataSet1.Tables(0).Rows(n).Item(2) = no
 Next

It wasnt until i tried this on a datatable with 40k+ row that i realized how slow it was!
It slows to a crawl and does only 2 loops or so a second (i have a i7 @ 4500Mhz)

Hopefully you're not going to say dont use a datatable as the whole program is built around that datatable and id hate to start again over this final stumbling block for me!!

by the way I tried it like this originally as well...
Code:
For Each dr As DataRow In DataSet1.Tables(0).Rows
     dr("Tested") = "No"
Next

hope someone can help :)
 
perfect. i hoped i was missing something simple.

thanks, you've taught me something very useful there:)
 
Back
Top