Solved

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

Posted on 2009-04-04
8
711 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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