1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why is this code so slow?

Discussion in 'Visual Basic .NET' started by tb303, Jan 28, 2013.

  1. tb303

    tb303 Power Member

    Joined:
    Dec 18, 2011
    Messages:
    585
    Likes Received:
    236
    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 :)
     
  2. jazzc

    jazzc Moderator Staff Member Moderator Jr. VIP

    Joined:
    Jan 27, 2009
    Messages:
    2,419
    Likes Received:
    9,841
    • Thanks Thanks x 1
    Last edited: Jan 28, 2013
  3. tb303

    tb303 Power Member

    Joined:
    Dec 18, 2011
    Messages:
    585
    Likes Received:
    236
    perfect. i hoped i was missing something simple.

    thanks, you've taught me something very useful there:)
     
    • Thanks Thanks x 1