how to execute SQL queries and retrieve their results using ADO.NET
how to display data that is read from a database
how to handle data access errors
Introducing ADO.NET
In previous chapters, we learned how to use Visual Web Developer and SQL
Management Studio to connect to a database and execute SQL queries. Now,
its time to apply this knowledge. Within our web application, well use
ADO.NETs classes to connect to the database; well then use that connection
to execute SQL queries.
ADO.NET 2.0 and Generic Data Access
ADO.NET is able to use different types of data connections, depending on
the kind of database to which the application is trying to connect. The
ADO.NET classes whose names start with Sql (such as the previously
mentioned SqlConnection, SqlCommand, etc.) are specifically built to
connect to SQL Server.
Similar classes are provided for other databasesfor example, if youre
working with Oracle, you can use classes such as OracleConnection,
OracleCommand, and so on. If, on the other hand, youre working with
database systems for which such classes are not specifically designed, you
can use generic low-level interfaces; most databases can be accessed through
the OLE DB interface (using classes such as OleDbConnection and
OleDbCommand), or the older ODBC interface (using classes such as
OdbcConnection and OdbcCommand).
In this book, well use only the Sql classes, but its good to know that you
have options!
In order to use ADO.NET, we must first decide which kind of database well use,
and import those namespaces containing classes that work with the database.
Since were using SQL Server, youll need to import the System.Data.SqlClient
namespace. This contains all the required Sql classes, the most important of
which are:
SqlConnection
This class exposes properties and methods for connecting to an SQL Server
database.
332
Chapter 9: ADO.NET

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.