Solved

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

Posted on 2009-04-04
8
721 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
[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
  • 3
  • 3
  • 2
8 Comments
 
LVL 48

Expert Comment

by:jpaulino
ID: 24066504
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
ID: 24066513
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
ID: 24066519
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 24

Accepted Solution

by:
Jeff Certain earned 400 total points
ID: 24067600
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
 
LVL 6

Expert Comment

by:Ramone_Hamilton
ID: 24067681
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
ID: 24067696
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
ID: 24067796
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
ID: 24067807
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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