What is the difference between data adapter and data reader?
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.
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.
Data Reader is an object used in connected Environment. Data Adapter is an object used in Disconnected environment using Dataset.
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.
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 whereasDataReader
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 whereasDataReader
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 aDataSet's
contents while disconnected from the Datasource and send any modified data back for processing using a relatedDataAdapter
whereasDataReader
can only read data from a Database & cannot modify it. DataAdapter
object is used to read the data from database and populates that data toDataSet
whereasDataReader
simply reads the data using theRead() method
.DataAdapter
is comparatively slower whereas usingDataReader
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.
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.
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
© 2022 - 2024 — McMap. All rights reserved.