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
552 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 74

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

13 Experts available now in Live!

Get 1:1 Help Now