Differences between ADO. NET DataReader and DataAdapter,

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.