|
-
Aug 7th, 2007, 08:29 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Aug 7th, 2007, 08:33 AM
#2
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.
-
Aug 7th, 2007, 10:02 AM
#3
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|