Using ADO.NET • Chapter 9
Which object allows for faster reading of data, the DataReader or the DataSet?
As always, testing is the ﬁnal determination, but generally, the DataReader is
faster than the DataSet.The DataReader is intended to provide a scrollable
source of data that provides access to data one row at a time. If you are
returning a great number of rows, then the DataReader may be a better idea
than the DataSet.Your testing will determine if the DataSet is better for
smaller amounts of data.
Should I use the OLE DB data provider or the SQL data provider?
If your project is using SQL Server in production, then by all means use the
SQL data provider.The SQL data provider is more efﬁcient and faster than
the OLE DB libraries, which is the only advantage that I see. Both objects
have the same options and methods; the differences lie in the implementa-
tion.The OLE DB data provider will allow you to change the DataSource
easily without having to change much code.
Should I use SQL statements or stored procedures for data access?
Stored procedures are the preferred method of data access, as they allow for
another layer of granularity to your application. Most relational databases also
precompile, and take the opportunity to optimize the query plan of the
stored procedure based on index statistics.They do, however, require other
specialized skills that may not be available on your team. In general, I would
use SQL statements as a last resort, or in special instances.
When should I use output parameters?
Output parameters have less overhead than returning data from a stored pro-
cedure. If you are returning a couple of pieces of data, or even an entire row
of data, it is more efﬁcient to use the output parameters. It is, however, much
Frequently Asked Questions
The following Frequently Asked Questions, answered by the authors of this book,
are designed to both measure your understanding of the concepts presented in
this chapter and to assist you with real-life implementation of these concepts. To
have your questions about this chapter answered by the author, browse to
www.syngress.com/solutions and click on the “Ask the Author” form.