ienumerable, arraylist and datatable

D

David

Hi all,

I am following this code...
http://www.devarticles.com/c/a/C-Sharp/Interface-IEnumerable-and-IEnumerator-in-C-sharp/2/

I have come to the part with public Customers(). I am assuming this is a
constructor (as it is the same name as the class).

In here, it says Get all customer ids from the database and put into an
arraylist. However, the code is for enumeration. To me, all data from a
database is enumerable, so why put into an arraylist?

What I want to do is to make this work with a datatable. Surely, I don't
need to enumerate each datarow in the datatable, just to put it into an
arraylist. If I am correct in my thinking, then how do I make this work with
a datatable instead of arraylist?

Thanks for your help. (Hopefully, this is not as difficult a problem as the
other one I raised in this group on 9th Nov, structure of website. That
issue is still a problem as well.)

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
D

David

Aaarrgghh!!!.

I think I got it, though please do tell me if I am wrong...

DataTable.Rows.GetEnumerator()

However, if anyone can give me a start on how I can use the SortByName and
SortByID functions from the article link in my original message, I would
appreciate it. Just a quick example or pseudo code to get me started.

Best regards,
Dave Colliver.
http://www.LiverpoolFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
 
G

Guest

David,
If you want to Sort A DataTable, it has a DefaultView. You can set the Sort
property on this and bind to the sorted view without going through all the
pain you describe. Of course, if you actually "need" an ArrayList you could
certainly write some code to convert the sorted DataView to one.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
 
S

sloan

David,

The author did a good job of showing how to manual implement certain
Interfaces.
Another option (esp in 1.1 and you know the object you want to "collect") is
to subclass CollectionBase.

Check this entries.

http://sholliday.spaces.live.com/blog/


5/24/2006
If you're used 1.1, check this entry.


6/5/2006
If you're using 2.0, check this entry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top