Results 1 to 3 of 3

Thread: [RESOLVED] [2005] For.....Next Loop Help Please

  1. #1

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Resolved [RESOLVED] [2005] For.....Next Loop Help Please

    Hello,

    I'm having a problem with a For....Next Loop and I don't know how to get round it.

    Basically I fill a Dataset (m_TDS) with rows of data, and I want to loop through this.

    My code is :

    Code:
    Dim i As Integer = 0
    For i = 0 To UBound(m_TDS.Tables(0).Rows)
         blah, blah, blah
    Next i
    However I get the blue line under the stuff in the brackets, and a message saying : "value of type 'system.data.datarowcollection' cannot be converted to 'system.array'"

    Does anyone know how I can get this to work please ?

    I appreciate any help anyone can offer.

    Thank you.

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

    Re: [2005] For.....Next Loop Help Please

    Firstly, UBound applies to arrays and nothing else. As you were typing that code Intellisense would have told you that. Secondly, don't use UBound for arrays anyway. For arrays use their GetUpperBound method. For collections, which the Rows property of a Datatable is (DataRowCollection to be precise), you have to subtract 1 from the Count property value.

    Unless you need the index for some reason I'd suggest a For each loop rather than a For loop anyway.
    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

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Re: [2005] For.....Next Loop Help Please

    Thanks jmc, that works a treat.

    I've also taken your advice on using a For....Each Loop aswell.

    Thanks.

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