Solved

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

Posted on 2013-01-12
2
568 Views
Last Modified: 2013-03-07
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
0
Comment
Question by:obb-taurus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38770677
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
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 38809468
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question