What is the difference between data adapter and data reader?
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.
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.
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.
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.
Here is a nice article on the above topic: Difference Between DataReader, DataSet, DataAdapter and DataTable in C#
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). 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.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With