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
554 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net mvc input file 2 32
Trying to use colormap to replace color in png, with a gradient to transparent 7 31
Runtime Error 2 28
Error on Add method 1 37
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now