Why datareader is used
The ADO. NET DataSet can also be used to represent hierarchical rowsets by using parent-child relationships between tables. The following code example uses the MSDataShape Provider to generate a chapter column of orders for each customer in a list of customers. Set the type of the parameter to OracleType. The OracleCommand. ExecuteReader method. You can then call the OracleDataReader. Although the parameters in your OracleCommand. Cursor to the OracleCommand. Parameters collection. The following code returns the results of the previous command using the Read and NextResult methods of the OracleDataReader.
The following example uses the previous command to populate a DataSet with the results of the Oracle package. You can use the FillError event to determine if an OverflowException has occurred.
Feedback will be sent to Microsoft: By pressing the submit button, your feedback will be used to improve Microsoft products and services. Privacy policy. Skip to main content. C ADO. SqlException: Login failed for user. Mail to : feedback net-informations. All other trademarks are property of their respective owners. SiteMap Terms About.
DataReader is a connection-oriented service; so, whenever you want data, you must be connected to the database. It allows you to retrieve read-only and forward-only data from a database.
In other words, a DataReader is a stream of data that is returned from a database query. It reads only one row at a time from the database and can only move forward.
This helps application performance since only one row of data is stored at a time. However, the DataReader cannot edit data while traversing over it. DataSet is an in-memory representation of data. Unlike DataReader, it has a disconnected nature, meaning you fill data in DataSet once and then get data from DataSet instead of connecting with the database. A great plus about DataSet is that it can be filled using multiple data sources.
The DataSet represents a complete set of data among the tables that include related tables, constraints, and relationships. However, this greater functionality comes with performance overhead; therefore, DataSet is slower than DataReader.
DataReader provides faster performance, but has read-only and forward-only access. DataSet, on the other hand, is high resource-consuming, but offers more control and a disconnected nature.
As a rule of thumb, if you want forward-only access to query results, and do not need to edit data, then DataReader is the better option due to its speed.
0コメント