Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Tuesday, 10 February 2015

Introduction:

We use DataSet and DataReader to store data from the data source while developing asp.net application. Some time we use Dataset and sometime use data reader, but most of us don’t know the difference between DataSet andDataReader and when to use which Dataset or Data-Reader.
DataSet Vs DataReader
1.        Forward Only:     DataReader is read-only (cannot update/manipulate data back to datasource) and forward-only (cannot read backward/random) . It provides the ability to expose the data from database while DataSet is a collection of in-memory tables.

2.       Speed:  DataReader fetches the records from database and stores in the network buffer and gives whenever requests. It releases the records as query executes and do not wait for the entire query to execute. Hence very fast as compare to the DataSet which releases the data after loading all the data in memory.
3.       Performance: As one row at a time is stored in memory in DataReader it increases application performance and reduces system overheads while there is more system overheads in DataSet as it fetches all the data from the datasource at a time in memory.

4.       fetch Random records: As DataReader is forward only, we can’t fetch random records as we can’t move back and forth .While in DataSet we can move back and forth and fetch records randomly as per requirement.

5.       DataReader fetches data from a single table while DataSet can fetch data from multiple tables.
6.       Relation Ship B/W Tables: As DataReader can have data from a single table so no relationship can be maintained while relationship between multiple tables can be maintained in DataSet.

7.       DataReader is read only so no transaction like insert, update and delete is possible while these transactions are possible in DataSet.

8.       DataSet is a bulky object that requires large memory space as compared to DataReader .

9.       DataReader is a connected architecture: The data is available as long as the connection with database exists while DataSet is a disconnected architecture that automatically opens the connection, fetches the data into memory and closes the connection when done.
10.   DataReader requires connection to be open and close manually in code while DataSet automatically handles it.
11.   Serialization:  DataSet can be serialized and represented in XML so easily passed around to other tiers butDataReader can't be serialized.
12.   Use In Webservices:  Since DataSet can be serialized it, can be used in wcf services  and web service that will return retrieved data. But DataReader can’t be serialized so can’t be used in wcf services and web services.


13.   Scope: When you need to navigate through the data multiple times then DataSet is better choice e.g. we can fill data in multiple controls But DataReader can only be read once so it can be bound to a single control and requires data to be retrieved for each control.

Categories: , ,

0 comments:

Post a Comment