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

DataTable vs ArrayList with custom Objects

P: n/a
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
Share this Question
Share on Google+
1 Reply


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