Differences between ADO. NET DataReader and DataAdapter,
DataReaderIs a forward pointer and does not contain data. When you call the Read () method once, it goes forward to the next recordDataReaderAn open database connection must be used separately.
In useSqlDataReaderThe associated SqlConnection is busySqlDataReaderService. You cannot perform any other operations on SqlConnection. Unless you callSqlDataReaderOtherwise, it will remain in this status.
DataAdapterLike a bridge, a database table is connected at one end, and a DataSet or able is connected at one end. After the data in the database is filled into the DataSet or DataTable, you can "bridge the river" without connecting to the database, instead, you can directly obtain data from DataSet or DataTable.
SqlDataAdapterMany methods are provided to facilitate operations on certain data sets, such as filling a query result into a able or DataSet, which is actually similar: create a SqlCommand and execute "Select * from [Table]". Then execute the ExcuteReader () method to obtain an IDataReader object. Then, read data row by row and put it in a collection object (such as DataTable) after testing, if there is a large amount of data operations, it is best to write the SqlCommand by yourself.SqlDataAdapterDatabase operations are much faster
SqlDataReaderOnly the database can be read, and the operated tables must be connected. However, to perform database write operations, you can only use the SqlCommand class,SqlDataAdapterIt is built on the SqlCommand object. It has all functions of the SqlCommand class, and can fill data into the DataSet object without connecting to the database, instead, you can directly obtain data from DataSet or DataTable. (Because it adopts the connectionless Transmission Mode)
UseDataReaderObjects can get read-only and forward data streams from the database. They can also improve application performance and reduce system overhead. At the same time, only one row is recorded in the memory.
SqlDataAdapterThe object can automatically open and automatically close the database connection (without human management). The main workflow of the adapter is that the SqlConnection object establishes a connection with the data source. The SqlDataAdapter object is returned toSqlDataAdapterFinallySqlDataAdapterThe object is added to the Ables object of the DataSet object.
Microsoft extended reading: https://msdn.microsoft.com/zh-cn/zh-ch/library/ms254931.aspx