Database Access with ADO.NET

ADO.NET is an interface library that provides access to various kinds of data providers, such as SQL, OLE DB, and ODBC. Although each data provider has its own set of classes, they are conceptually the same. The main classes are as follows:

  • Connection: Used to establish a connection to a database; this connection is necessary to execute a command or read data. To connect to an SQL database, you use the SqlConnection class; an OdbcConnection class is used to connect to an ODBC data provider.
  • Command: Executes a database command such as SELECT, INSERT, or UPDATE. Requires a database connection.
  • DataReader: Exposes the data resulting from the execution of a SELECT command.

Although the classes that establish a database connection and execute commands are specific to the type of the data source, the database commands themselves are all based on SQL and are mostly compatible between the various kinds of data sources. The commands needed for this project are SELECT, INSERT, and UPDATE.

To promote cost efficiency, we store the customer information in a Microsoft Excel sheet, which is specified in the application's configuration file. The ODBC service has an Excel driver that can be used to store the customer records in an XLS file. However, we will encapsulate all database dependencies in an additional layer to allow the replacement of the data provider later based on growth of the business.

Figure 12.3 shows the class diagram for the data access layer. DataTable is a simple .NET Framework class for caching the content of a database table, in our case the customer table. CustomerDB is an abstract class providing higher-level API functions specific to the kind of operations performed by Online Photo Shopnamely, validating login credentials and creating a new user account. CustomerDB also defines an abstract method to create a new DbDataAdapter instance. This method must be implemented by inherited classes because it is specific to the data source type. For now, SqlCustomerDB will not be implemented. It is shown only to visualize how this possible future change can be addressed.

Figure 12.3. Class Diagram for Database Access Utilities


Introducing .NET

Introducing Software Engineering

A .NET Prototype

Project Planning

The Photo Editor Application

GDI+ Graphics Extensions

Advanced GDI+ Operations

Dynamic Loading of Components

Accessing System Resources

Performance Optimization, Multithreading, and Profiling

Building the Web Application with ASP.NET

Security and Database Access

Product Release

. NET-A Complete Development Cycle
.NET-A Complete Development Cycle
ISBN: 0321168828
EAN: 2147483647
Year: 2005
Pages: 123 © 2008-2020.
If you may any questions please contact us: