?
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
Medium Priority
?
576 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 2000 total points
ID: 38809468
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 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