473,396 Members | 1,917 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ienumerable, arraylist and datatable

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
3 5879
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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
3
by: elvis_the_king | last post by:
Hi all, I am asking myself wheter IEnumerable has any inherent semantics? The docs seem to be very unclear to me. More specifically: When using a "foreach(...)" construct to enumerate a...
16
by: stojilcoviz | last post by:
I've a datagrid whose datasource is an arraylist object. The arraylist holds many instances of a specific class. I've two questions about this: 1 - Is there a way by which I can obtain a...
15
by: Gustaf | last post by:
Using VS 2005. I got an 'IpForm' class and an 'IpFormCollection' class, containing IpForm objects. To iterate through IpFrom objects with foreach, the class is implemented as such: public class...
13
by: David | last post by:
Hi all, I have a singleton ienumerable that collects data from a database. I have listed the code below. It has the usual methods of current, move and reset. I need to go to a certain position...
0
by: Ronald S. Cook | last post by:
Using LINQ, I can bind my IEnumerable to my ComboBox no problem. However, in the past it would be a DataTable that I could insert a new row (e.g. "(Please select...)") and then sort it with a...
2
by: Ronald S. Cook | last post by:
Does anyone know how to convert an object of type IEnumerable to a DataTable? Thanks, Ron
3
by: Peter Morris | last post by:
I've given this interface some thought, the benefits to using it seem to be 01: I can use "var" in a foreach //Works List<SomeClasslist = new List<SomeClass>(); foreach(var item in list)...
11
by: KMinFL | last post by:
This is a C# VS 2008 question... Our system has 2 base classes, SingleEntity and NewPluralEntity. SingleEntity provides access to properties and methods related to manipulating data in a database...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.