what are difference between dataset and datareader

Posted By  oudinia On 16 Apr 2010 23:04:44
emailbookmarkadd commentsprint
No of Views:725
Bookmarked:0 times
Votes:0 times

Introduction

In this tips, explore, what are difference between dataset and datareader.

 

DataSet:
1. used to retreive data in a disconnected manner.
2. can be serialized and transported to another system (using xml)
3. extremely flexible for manipulating data.

DataReader:
1. used to retreive data in a connected manner, until closed.
2. cannot be serilized, and is used only for read scenarios.

Internal functionning of the dataset:
1. it uses a DataReader to retreive its data, and then disconnect.
2. its structure is persisted in memory or using xml.

in this case, it is useless to use the dataset, in order to fill another structure such as a generic list System.Collections.generic.List, System.Collections.generic.List(Of T).

It is better to use a datareader to fill a generic list.

for more information on this:
perfomance check list for ado.net
http://msdn2.microsoft.com/en-us/library/ms998589.aspx
Imporving ADO.NET performance
http://msdn2.microsoft.com/en-us/library/ms998569.aspx

 

Further thoughts : with the entity framework, we have another level of abstraction. Yet, we still need datasets for their many capabilities (caching, compatibility with reporting services, xml data persistance and more...). the DataSet is here to stay for many scenarios.

Finally, the dataset is perfect for implementing the "Data Transfer Object" pattern, which is explained here : http://msdn.microsoft.com/en-us/library/ms978717.aspx

Happy Programming

Sign Up to vote for this article
Other popular Tips/Tricks
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top