467,899 Members | 1,508 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,899 developers. It's quick & easy.

DataTable vs ArrayList with custom Objects

I am wondering what is the cost of using DataTable.

Lets say i have 1000 Employee records. The object oriented purist will require the Data Layer to return an ArrayList with 1000 Employee objects.

But very often we (at least i) returning DataTable to populate the grid.
But now i am wondering: Am i gaining anything?

The DataTable has to create object DataRow for each row. Versus i am creating Employee object for each row.

So unless DataTable does not create 1000 of objects I am actually loosing the benefits of using strong type and gaining nothing.

Am i correct?

Thanks.
George

Nov 18 '05 #1
  • viewed: 1688
Share:
1 Reply
George:

Your analysis is correct.

The DataTable does provide other features, like the ability to Select
rows and can work in a sorted, filtered, view. As part of a DataSet it
can also persist to an XML file and back again. If these are not
features you need, or are features you have the time to implement, you
still won't be gaining anything.

Some of the code generation tools today do a great job of writing the
code for a custom collection of your business objects. With this
approach you don't lose *any* strong typing (since the ArrayList can
only return object references, which is a bummer, but 2005 will take
care of this someday).

--
Scott
http://www.OdeToCode.com

On Tue, 17 Aug 2004 14:25:50 -0400, "George" <no****@hotmail.com>
wrote:
I am wondering what is the cost of using DataTable.

Lets say i have 1000 Employee records. The object oriented purist will require the Data Layer to return an ArrayList with 1000 Employee objects.

But very often we (at least i) returning DataTable to populate the grid.
But now i am wondering: Am i gaining anything?

The DataTable has to create object DataRow for each row. Versus i am creating Employee object for each row.

So unless DataTable does not create 1000 of objects I am actually loosing the benefits of using strong type and gaining nothing.

Am i correct?

Thanks.
George


Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Omer | last post: by
5 posts views Thread by Dalibor Kusic | last post: by
4 posts views Thread by John Kandell | last post: by
6 posts views Thread by gane kol | last post: by
4 posts views Thread by =?Utf-8?B?YmFzdWxhc3o=?= | last post: by
4 posts views Thread by StinkyDuck | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.