What is the difference between data adapter and data reader?
7 Answers
Please see DataReader, DataAdapter & DataSet - When to use? :
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.
- 21,988
- 13
- 81
- 109
- 344,730
- 71
- 640
- 635
-
Just presenting a link? Is it not a comment? – Mehdi Khademloo Jun 29 '16 at 22:35
A DataReader is an object returned from the ExecuteReader method of a DbCommand object. It is a forward-only cursor over the rows in the each result set. Using a DataReader, you can access each column of the result set, read all rows of the set, and advance to the next result set if there are more than one.
A DataAdapter is an object that contains four DbCommand objects: one each for SELECT, INSERT, DELETE and UPDATE commands. It mediates between these commands and a DataSet though the Fill and Update methods.
- 160,644
- 26
- 247
- 397
Data Reader is an object used in connected Environment. Data Adapter is an object used in Disconnected environment using Dataset.
- 51
- 1
- 1
DataReader is a faster way to retrieve the records from the DB. DataReader reads the column. DataReader demands live connection but DataAdapter needs disconnected approach.
- 36,151
- 76
- 250
- 438
- 41
- 1
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.
DataAdapterfollows connectionless-oriented architecture which simply means you need not necessarily be connected to a data-source whereasDataReaderis a connection-oriented architecture which means it needs an active connection to a data-source for it to operate.DataAdapteris an intermediate layer/ middleware which acts a bridge between the DataSet and a Database whereasDataReaderprovides forward-only, read-only access to data using a server-side cursor (simply put it is ued to read the data).- Using
DataSetwe can manipulate and update aDataSet'scontents while disconnected from the Datasource and send any modified data back for processing using a relatedDataAdapterwhereasDataReadercan only read data from a Database & cannot modify it. DataAdapterobject is used to read the data from database and populates that data toDataSetwhereasDataReadersimply reads the data using theRead() method.DataAdapteris comparatively slower whereas usingDataReadercan 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.
- 2,290
- 20
- 16
Data reader is an object through which you can read a sequential stream of data. it's a forward only data wherein you cannot go back to read previous data. data set and data adapter object help us to work in disconnected mode. data set is an in cache memory representation of tables. the data is filled from the data source to the data set thro' the data adapter. once the table in the dataset is modified, the changes are broadcast to the database back thro; the data adapter.
- 21
- 1
DataAdapter
DataAdapter will acts as a Bridge between DataSet and database. This dataadapter object is used to read the data from database and bind that data to dataset. Dataadapter is a disconnected oriented architecture.
DataReader
DataReader is used to read the data from database and it is a read and forward only connection oriented architecture during fetch the data from database. DataReader will fetch the data very fast when compared with dataset. Generally we will use ExecuteReader object to bind data to datareader
- 13,575
- 26
- 81
- 144
- 21
- 1