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!