Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 739
  • Last Modified:

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

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
rflorencio
Asked:
rflorencio
  • 3
  • 3
  • 2
2 Solutions
 
jpaulinoCommented:
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
 
jpaulinoCommented:
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
 
Ramone_HamiltonCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Jeff CertainCommented:
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
 
Ramone_HamiltonCommented:
I didn't know about datatables having problems with items over 1k entries.  Thanks for that bit of info.
0
 
Jeff CertainCommented:
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
 
Ramone_HamiltonCommented:
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
 
Jeff CertainCommented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now