Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between data adapter and data reader?

Tags:

c#

.net

ado.net

What is the difference between data adapter and data reader?

like image 912
Novice Developer Avatar asked Jul 16 '09 18:07

Novice Developer


People also ask

What do you mean by DataReader?

In ADO.NET, a DataReader is a broad category of objects used to sequentially read data from a data source. DataReaders provide a very efficient way to access data, and can be thought of as a Firehose cursor from ASP Classic, except that no server-side cursor is used.

What is the difference between DataReader and DataAdapter in Ado net?

Using the DataReader can increase application performance both by retrieving data as soon as it is available, and (by default) storing only one row at a time in memory, reducing system overhead. A DataAdapter is used to retrieve data from a data source and populate tables within a DataSet.

What is difference between SqlDataReader and SqlDataAdapter?

A SqlDataAdapter is typically used to fill a DataSet or DataTable and so you will have access to the data after your connection has been closed (disconnected access). The SqlDataReader is a fast forward-only and connected cursor which tends to be generally quicker than filling a DataSet/DataTable.

What is the role of DataReader?

A data reader provides an easy way for the programmer to read data from a database as if it were coming from a stream. The DataReader is the solution for forward streaming data through ADO.NET. The data reader is also called a firehose cursor or forward read-only cursor because it moves forward through the data.


1 Answers

Here is a nice article on the above topic: Difference Between DataReader, DataSet, DataAdapter and DataTable in C#

Key differences in simple terms:

Unlike classic ADO, which was primarily designed for tightly coupled client/server systems,ADO.NET was built with the disconnected world in mind, using DataSets/DataAdapter.

  • DataAdapter follows connectionless-oriented architecture which simply means you need not necessarily be connected to a data-source whereas DataReader is a connection-oriented architecture which means it needs an active connection to a data-source for it to operate.
  • DataAdapter is an intermediate layer/ middleware which acts a bridge between the DataSet and a Database whereas DataReader provides forward-only, read-only access to data using a server-side cursor (simply put it is ued to read the data).
  • Using DataSet we can manipulate and update a DataSet's contents while disconnected from the Datasource and send any modified data back for processing using a related DataAdapter whereas DataReader can only read data from a Database & cannot modify it.
  • DataAdapter object is used to read the data from database and populates that data to DataSet whereas DataReader simply reads the data using the Read() method.
  • DataAdapter is comparatively slower whereas using DataReader can increase application performance both by retrieving data as soon as it is available, and (by default) storing only one row at a time in memory, reducing system overhead.
like image 80
Tahir77667 Avatar answered Nov 15 '22 13:11

Tahir77667