By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,814 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,814 IT Pros & Developers. It's quick & easy.

ienumerable, arraylist and datatable

P: n/a
Hi all,

I am following this code...
http://www.devarticles.com/c/a/C-Sha...-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
Nov 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi all,

I am following this code...
http://www.devarticles.com/c/a/C-Sha...-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

Nov 12 '06 #2

P: n/a
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


"David" wrote:
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
"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi all,

I am following this code...
http://www.devarticles.com/c/a/C-Sha...-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


Nov 13 '06 #3

P: n/a

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.

"David" <da*****************@revilloc.REMOVETHIS.comwrot e in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi all,

I am following this code...
http://www.devarticles.com/c/a/C-Sha...-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


Nov 13 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.