Is DataReader or DataSet used?

Source: Internet
Author: User

Editor's note: Is DataReader or DataSet used? First, you need to know the similarities and differences between them and the applicable working environment. After learning about this information, you can easily solve the problem when to use it. The following describes how to differentiate data.

I collected it online and used DataReader or DataSet. The answer below is clear.

Use both DataReader and DataSetData can be read from the data source..

DataReader itself isBuilt using the IDbCommand. ExecuteReader () method;

While DataSet isUse the DbDataAdapter. Fill () method to Fill.

In addition,The two work in a significantly different way.:

DataReaderThe execution process cannot be separated from the database connection, that is, the IDbConnection. Close () method cannot be used to Close the database connection when the DataReader reads data;

In useDataSetWhen obtaining data, you can disconnect the database because DbDataAdapter is already responsible for retrieving data to the application server.

If the data size is small and the website size is small, it doesn't matter which one to use. DataSet is required for frequent access.Because there is a connection problem.

In network application:

Reader must be in the Connection state before it can be used, so it is better for the component to return DataSet.

This is why the web service allows the returned dataset instead of datareader.

Reader occupies connection resources, so it is not very convenient. Dataset is a non-connected database access mechanism.

DataSet is slower than DataReader in test results, which is several times worse, but DataSet is better in ease of use.

The two are applicable in different environments, depending on the purpose of data binding.:

It is better to use DataReader to simply display it to the client for browsing, or to determine certain conditions in the program to determine the execution process of the program;

If you need to edit or modify the display results and submit the changes to the background database, you should not hesitate to select DataSet.

In addition, if the dataset Data Reading process needs to be connected, you can bind it again. The binding conditions can be bound according to the client selection or according to attributes similar to PageIndex, the data you actually need is not the entire data table.

In my personal sense, they all develop towards precision. BT transfers files, reads small pieces of data, and reads and transfers large image files, ajax only transmits the data to be transmitted on the webpage and receives the data to be received. This is a result of precision!

Related Article

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.