Results 1 to 3 of 3

Thread: Next row in a datatable loop?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Next row in a datatable loop?

    Hi all,

    Just curious is there a "next row" method when looping through a datatable?
    Basically, I want to be able to go to the next row without having to go to the end of the loop. See my coded example:

    Code:
    For Each row As DataRow In dt.Rows
    Dim MyCondition as Boolean = ClassConditions.ConditionA            
    
                Try
    If MyCondition = True then
    'I'd like something here that would go to next row
    end if
                Catch ex As Exception
    'error trapping code
                End Try
            Next row
    If I can't do it this way is there some alternative way of accomplishing? I'm using VB 2005

    Thanks,

    Strick

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Next row in a datatable loop?

    It's not specific to DataTables at all but you can use the Continue For statement in a For or For Each loop to jump to the next iteration. That said, it's often very simple to do the same thing without a Continue statement, usually by simply inverting an If condition. Can we see the whole code block?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Next row in a datatable loop?

    [edit] beat me to it
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

Posting Permissions

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



Click Here to Expand Forum to Full Width