Difference between datareader and dataset?

Answer Posted / madhavi

DATA Reader
The DataReader has a defined set of operations that revolve
around its connected, forward-only, read-only nature (the
read-only DataReader is also known as the firehose cursor of
ADO.NET). A DataReader is a stream of data that is returned
from a database query. When the query is executed, the first
row is returned to the DataReader via the stream. The stream
then remains connected to the database, poised to retrieve
the next record. The DataReader reads one row at a time from
the database and can only move forward, one record at a
time. As the DataReader reads the rows from the database,
the values of the columns in each row can be read and
evaluated, but they cannot be edited.

DATA Adapter
The DataSet is the main data storage tool in the ADO.NET
disconnected architecture. Unlike the DataReader, the
DataSet is not connected directly to a database through a
Connection object when you populate it. Instead, to fill a
DataSet from a database you first create a DataAdapter
object (such as a SqlDataAdapter) for the provider and
associate it with a SqlConnection object. Then the
SqlDataAdapter can broker the data retrieval for the DataSet
by issuing a SqlCommand against the database through the
SqlConnection, retrieving the data, and filling the DataSet.

You can think of the SqlDataAdapter as a bridge between the
connected and disconnected objects. One of its purposes is
to serve as the route for a rowset to get from the database
to the DataSet. For example, when the SqlDataAdapter's Fill
method is executed it opens its associated SqlConnection
object (if not already open) and issues its associated
SqlCommand object against the SqlConnection. Behind the
scenes, a SqlDataReader is created implicitly and the rowset
is retrieved one row at a time in succession and sent to the
DataSet. Once all of the data is in the DataSet, the
implicit SqlDataReader is destroyed and the SqlConnection is
closed.

Is This Answer Correct ?    40 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which keyword is used to accept variable number of parameters?

686


What is untyped dataset?

541


How to add an aggregate column?

533


Which parameter of ConnectionString is used to specify the name of the database?

547


What are the different methods by which we can populate a dataset?

689






Which is better entity framework or ado.net?

509


What are the usages of the command object in ado.net?

552


What are the various methods provided by the DataSet object to generate XML?

589


What is the full form of ado?

514


Define data access layer?

531


What is the role of the dataset object in ado.net?

571


What is oledb driver?

497


What is the default provider in ado.net?

514


What property must be set and what method must be called in your code to bind the data from some data source to the Repeater control?

556


Give an example of a .net application which connects to microsoft access database using ado.net classes.

589