Solved

asp.net vb.net main difference betwen datatable and dataset

Posted on 2009-04-04
8
703 Views
Last Modified: 2012-05-06
Some times the DataTable and DataSet objects still make me a little confused, what is the main difference between them and when I use each.
0
Comment
Question by:rflorencio
  • 3
  • 3
  • 2
8 Comments
 
LVL 48

Expert Comment

by:jpaulino
Comment Utility
From MSDN:
The DataSet, which is an in-memory cache of data retrieved from a data source, is a major component of the ADO.NET architecture. The DataSet consists of a collection of DataTable objects that you can relate to each other with DataRelation objects.  
 http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx
0
 
LVL 48

Assisted Solution

by:jpaulino
jpaulino earned 100 total points
Comment Utility
Also look to this diagram to understand that the dataset is a in-memory representation that can have one or more datatables.
http://msdn.microsoft.com/en-us/library/zb0sdh0b.aspx
0
 
LVL 6

Expert Comment

by:Ramone_Hamilton
Comment Utility
Datasets are essentially a collection of Datatables.  When you use them is based off of the data you are holding.  If you are dealing with one set of data, that would all go into one location, the DataTable would be better.  If you are dealing with a multitude of data that needs to be seperated or grouped a specific way, a DataSet is better.
0
 
LVL 24

Accepted Solution

by:
Jeff Certain earned 400 total points
Comment Utility
In addition to the comments already posted...

1. You can bind girds, listboxes, etc to either a datatable or a dataset. If you bind to a dataset, you'll need to specify the DataMember (i.e. the tablename) in addition to the datasource. (Caveat: some third-party libraries will assumer that you want to bind to DataSet.Table(0) if you don't specify the DataMember.)
2. DataSet has a fair amount of overhead associated with it. DataTable does too, but it gets somewhat worse if you throw DataTable into the mix when you don't need to. You're better of using objects whenever possible.
3. DataTables don't scale well. If you're putting more than about 1000 entries into them, you'll want to use an alternative storage mechanism. See http://msdn.microsoft.com/en-us/library/dd364983.aspx
4. Keep in mind that DataTables are disconnected -- that is, changes to them don't immediately result in changes to the database; you'll have to explicitly update the database.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Expert Comment

by:Ramone_Hamilton
Comment Utility
I didn't know about datatables having problems with items over 1k entries.  Thanks for that bit of info.
0
 
LVL 24

Expert Comment

by:Jeff Certain
Comment Utility
It's not so much that it has "problems" as the fact that it's slow doing DataTable.Select against tables that have more than a thousand or so entries... and painfully slow when you're in the 50K+ range. I should maybe have been more clear.
0
 
LVL 6

Expert Comment

by:Ramone_Hamilton
Comment Utility
You were perfectly fine.  In fact, you have given me insight over a problem I had recently with reading in 250+k rows into a datatable and selecting against it.
0
 
LVL 24

Expert Comment

by:Jeff Certain
Comment Utility
Wonderful! Glad I could help on that.

If you haven't already, and you're targeting 3.5, you really, really want to look at LINQ as a possible performance improvement.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

14 Experts available now in Live!

Get 1:1 Help Now