Is it best practice to use dataset or data tables to return data from a database in 3 layer design?

I've been reviewing examples on the web of 3 layer design and I've noticed that most samples return either datasets or data tables. The thing that is confusing me is what if you would rather return a generic list of type so you can utlize properties or methods from within the type your list is based on? As example using a Name property that concats various fields in a specific way depending on the data, if the List is bound to a control on a form then the Name property can be used as the datafield. If you would want to accomplish the same thing when using a dataset or table, you'd have to return the data from the database to acheive the same (I try not to use datasets or datatables so I'm probably very wrong about this statement. :) )

The part that is really confusing me is about resusing code, to me it seems the only way to reuse code is to retrieve the data into either a dataset or datatable and then loop through the data and add it to a List, is this generally the best practice for 3 layer or is there a way to do this without datasets and datatables.

The example in the link below demonstrates in essence using datasets or tables and then adding it to an object but I'm forced to ask if this is the best practice?

http://www.codeproject.com/Articles/36847/Three-Layer-Architecture-in-C-NET

I'm not looking for a solution using the Entity Framework as that is an area I haven't explored yet.

Thanks
obb-taurusAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
käµfm³d 👽Commented:
I'm not looking for a solution using the Entity Framework
Well entities (not necessarily EF) are the new hotness right now. But since you don't want to go down that road yet...

it seems the only way to reuse code is to retrieve the data into either a dataset or datatable and then loop through the data and add it to a List
I'm not sure why you would loop through the data and add it to a list, unless there was something you wanted to do with the data that required a List data structure. You can easily data bind either a DataSet or a DataTable to various data controls in .NET.

As to the difference between the two, a DataSet is a collection of one or more DataTables; a DataTable is a group of records (rows with columns) that represent some data source. I suppose if you are only working with one table (or pseudo-table), then a DataTable would be lighter-weight. If you have multiple tables, then DataSet could be more appropriate.

Two things to note:

1.

When I say "multiple tables" above, I am not necessarily talking about a query that uses multiple tables (e.g. a JOIN query). Rather I mean you select a subset of rows from two different tables in two different queries. When I say "pseudo-table" above, I am referring more to a JOIN query.

2.

Don't make the assumption that a DataTable always represents a database table. You can easily load an XML file into a DataTable (or DataSet) if it is structured correctly.
0
All Courses

From novice to tech pro — start learning today.