An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

DataReader, DataAdapter & DataSet - When to use?

Monday, April 25, 2005 7:54 AM
ADO.NET offers two central Data Access Components. In this Article we will discuss about their features and when to use what.

ADO.NET provides two central Data Access Components. The excellent thing is that, they are common across all Databases, be it SQL Server or other competitive databases. Its only the namespace to be used, that differs, while using a Database other than SQL Server.

The two Data Access Compnents are:


1. DataSet

2. The .NET data provider, which is a set of components including the Connection, Command, DataReader, and DataAdapter objects.


Its common that the doubt arises on when to use DataReader and DataAdapter, DataSet.

The thumb rule I would suggest is,


1. If your Data access operations is mainly fetching and displaying the records and doesnt involve insert/update/delete statements and other manipulations (forward only, read only) actions, go for the DataReader.


DataReader offers a forward only read stream of access to the records. It is very useful in cases where we just grab the data from the database to display in DataGrid, Label and other Webcontrols.

However, DataReader requires the connection with the database open until its operation is completed.


2. If your Data access operations extend to as simple as an Insert/Update/Delete statement to as complex as using it as a return type from a web service, go for the DataSet. The DataSet has the following advantages.


i. Complex Data type supporting numerous methods such as ReadXML which reads new XML data to form a dataset, WriteXML which provides an XML format of the existing data, etc.,

ii. Works on the disconnected architecutre i.e. The connection doesnt need to be on for the DataSet to perform the manipulations and other actions and is required only at the time of Updating the records to the Database Table.

iii. Provides an In-memory representation of the Data. Can contain one or more DataTable objects that have primary key, foreign key, and constraints between them and can enforce constraints such as unique or be configured to ignore them
iv. Has Individual elements such as DataTable, DataRow and DataColumn to access specific values.

v. While using DataSet and DataAdapter, you don't need to explicitly open the connection. DataAdapter automatically opens and closes the connection as and when required.

Hope it provided some insight into DataReader, DataSet and DataAdapter.

Thanks.


Feedback

# re: DataReader, DataAdapter & DataSet - When to use?

Information you have provided is fabulous 3/10/2006 10:27 AM | Suman

# re: DataReader, DataAdapter & DataSet - When to use?

Great, thanks for the information. 3/24/2006 6:53 PM | Jon Brune

# re: DataReader, DataAdapter & DataSet - When to use?

Provided info is too good, it is explained in a very efficient and simple manner. 4/7/2006 3:41 PM | Deepika

# re: DataReader, DataAdapter & DataSet - When to use?

Plz Describe more about the Data Set and Data Adapter.This is an ecellent article about the data reader and dataset. 5/3/2006 7:09 AM | Ali Imran Ahmad

# re: DataReader, DataAdapter & DataSet - When to use?

doubts cleared by this article in a simple as well as greater manner 6/22/2006 2:05 PM | subburaj

# re: DataReader, DataAdapter & DataSet - When to use?

Its really very useful for the beginnners who are all working in ADO.NET 6/29/2006 5:04 AM | kesavan

# re: DataReader, DataAdapter & DataSet - When to use?

Really explained the use of datareader and dataset. Thanks for the information. 8/9/2006 1:06 PM | Sujith MS

# re: DataReader, DataAdapter & DataSet - When to use?

Provided info is too good, it is explained in a very efficient and simple manner. 1/16/2007 8:13 AM | Pravin P

# re: DataReader, DataAdapter & DataSet - When to use?

The information provided by u, is simly superb because a person with mere knowledge can understand it easily. 2/26/2007 12:56 PM | konda reddy

# DataReader, DataAdapter

DataReader, DataAdapter 3/31/2007 11:16 PM | LaYa

# re: DataReader, DataAdapter & DataSet - When to use?

asdsafsadaf 1/6/2008 2:25 AM | susindran

# re: DataReader, DataAdapter & DataSet - When to use?

Awesome.... Short and sweet information.. 1/16/2008 10:47 PM | sachin

# re: DataReader, DataAdapter & DataSet - When to use?

Its very clear and simple,even the new learners can understand it. 3/8/2008 12:26 PM | gayathri

# re: DataReader, DataAdapter & DataSet - When to use?

its awesum 4/2/2008 4:08 PM | rakesh

# re: DataReader, DataAdapter & DataSet - When to use?

Thaks for the great help. It's so clear and understandable. 5/4/2008 8:50 PM | Athula

# re: DataReader, DataAdapter & DataSet - When to use?

thanks for the information bro.. Keep it up.
5/26/2008 12:45 PM | code0910

# re: DataReader, DataAdapter & DataSet - When to use?

Thanks ,this information is very fabulous and easy . 6/4/2008 5:10 PM | Rabia

# re: DataReader, DataAdapter & DataSet - When to use?

As i am new to .net,the information you had given is very useful for me to proceed.
thank you 6/5/2008 5:36 PM | kokilaNaresh

# re: DataReader, DataAdapter & DataSet - When to use?

Thx for the greate help... :-)) 7/6/2008 6:52 PM | Mahesh Khadse

# re: DataReader, DataAdapter & DataSet - When to use?

fuudddduuuuu.... 7/25/2008 12:18 AM | hiiii

# re: DataReader, DataAdapter & DataSet - When to use?

the information given above is...MAHA FUUDDDUUUUU 7/25/2008 12:21 AM | Bond James Bond

# re: DataReader, DataAdapter & DataSet - When to use?

GOOD INFORMATION 7/25/2008 6:36 PM | JATIN 9855366988

# re: DataReader, DataAdapter & DataSet - When to use?

Thank you for the help 8/11/2008 3:35 AM | digish

# re: DataReader, DataAdapter & DataSet - When to use?

Good article.. 8/17/2008 6:04 PM | Aniket

# re: DataReader, DataAdapter & DataSet - When to use?

i got to know the diff between them and their functonality after studying this thank u 8/23/2008 4:25 PM | navnith

# re: DataReader, DataAdapter & DataSet - When to use?

dssds 9/3/2008 6:45 PM | sdss

# re: DataReader, DataAdapter & DataSet - When to use?

Wonderful explanation boss.
Thanks
coolcoder 9/6/2008 1:29 PM | coolcoder

# re: DataReader, DataAdapter & DataSet - When to use?

All the operation can perform to the Data reader in Database then what is the use to the DataAdapterin connect to the database 9/17/2008 3:52 AM | Atul Yadav

# re: DataReader, DataAdapter & DataSet - When to use?

Thanx 9/25/2008 1:58 AM | Piyush

Post a comment





 

Please add 1 and 2 and type the answer here: