Thanks to Gosia I got interested in ADO.NET objects like DataReader and DataAdapter. So what are they and how are they better from simple methods?
DataReader can retrive read-only, forward-only stream of data from a database and they are stored in a buffer on client side even if not all query have been executed yet. You use the Read method of the DataReader object to obtain a row from the results of the query. You can access each column of the returned row by passing the name or ordinal reference of the column to the DataReader.
Everything and more you can read at MSDN: http://msdn.microsoft.com/en-us/library/haa3afyz(VS.71).aspx
Here is an example from MSDN:
The DataAdapter serves as a bridge between a DataSet and a data source for retrieving and saving data. The DataAdapter provides this bridge by mapping Fill, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet. There are also inherited classes like: OdbcDataAdapter, OledbAdapter, SqlDataAdapter and so on to each supported database. Se more at MSDN site: http://msdn.microsoft.com/en-us/library/system.data.common.dataadapter(VS.71).aspx
Here is an example from MSDN:
So what is the difference?
-
dataReader can’t make update in a database, it can only read, dataAdapter has Update method,
-
dataAdapter is easier to use
-
you can’t serialize a dataReader so you can’t remote it
-
dataAdapter provides dataSet, that has great functionality, allow you manage DataRelation, Dataviews, DataTable.Select, Expression Columns etc.
-
dataReader is faster when you read large record set
I found very nice comparison of this two at: http://msmvps.com/blogs/williamryan/archive/2005/02/26/37015.aspx

