ADO.NET is the common name for the classes and interfaces of the System.Data second-level namespace of the FCL. Conceptually, ADO.NET can be divided into two distinct parts: the data access layer and the data storage system.
The classes associated with the data storage system are stand-alone classes that you can employ in any ADO.NET application. These classes include DataColumn, DataRelation, DataRow, DataSet, DataTable, and DataView. Of these, the most central class is DataSet.
Unlike the storage mechanism, which is defined around classes, the data access layer is formally defined using interfaces (abstract application programming interface definitions). Concrete classes—that is, classes that can be instantiated—associated with a particular data access mechanism implement these interfaces.
There are five data access mechanisms native to the version 1.1 FCL, which is also to say that Microsoft provides them. These are associated with the System.Data.SqlClient, System.Data.OleDb, System.Data.Odbc, System.Data.SqlServerCE, and System.Data.OracleClient third-level namespaces.
As is the case with ADO and OLE DB providers, database vendors are permitted, and warmly encouraged, to create their own data access classes that implement these same interfaces. Advantage calls their implementation the Advantage .NET Data Provider, and it can be found in the Advantage.Data.Provider namespace.
The primary responsibility of the Advantage .NET Data Provider classes is the same as that of the native implementations supply data to the data storage system, and in particular, insert data into DataTables. DataTables are the individual data stores that reside in a DataSet.
The second, and obviously crucial, role of data providers is to permit direct manipulation of a data source. This, too, is deftly handled by the Advantage .NET Data Provider.
There is one final point concerning ADO.NET that you should be aware of. For the most part, ADO.NET relies heavily on the client-side caching of records. Specifically, much of what you do with data in ADO.NET involves the manipulation of records that are stored in one or more DataSets, which are in-memory data stores.
While this style of data management is particularly well-suited for distributed computing, most developers take a while to get accustomed to it. For example, in ADO.NET, there are never pessimistic locks on records. You discover whether your changes can be applied to the underlying database or not when you finally attempt to apply the one or more changes in the cache.
This discussion is not meant to discourage you from ADO.NET. There’s a lot to like about it. However, due to ADO.NET’s reliance on features exposed by the DataSet and other related classes, you are less able to exploit all of ADS’s strengths compared with ADS’s other data access mechanisms. But, this is true with respect to ADO.NET and any other database server.
As is the case with all data access mechanisms described in this part of this book, the following discussion of ADS programming with ADO.NET touches on just a few of the available techniques, particularly those that apply to ADS. Unlike some of the other data access mechanisms covered in this part of this book, the native .NET classes provide a significant amount of standard database functionality, such as filtering, sorting, and seeking. Consequently, these topics are not ADS specific, and are not covered in this chapter. For a comprehensive discussion of ADO.NET programming, you may want to pick up a good book, such as ADO.NET, The Complete Reference, by Otey and Otey (McGraw-Hill/Osborne, 2003).
|ON THE CD|| |
The examples provided in this chapter can be found in the C# project CS_ADONET on this book’s CD-ROM (see Appendix B). This project was written in Visual Studio .NET 2003. If you are working with an older version of Visual Studio .NET, project format incompatibilities will prevent you from compiling the project as is. Nonetheless, the same classes and methods demonstrated in this project can be used in earlier .NET environments.
The main form of the CS_ADONET C# project used in the examples in this chapter is shown in Figure 15-1.
Figure 15-1: The CS_ADONET project in Visual Studio
Note that before you can use ADS with Visual Studio for .NET, you must add a reference to the Advantage.Data.Provider namespace. To do this, use the following steps:
From Visual Studio .NET, select Projects | Add Reference. Visual Studio displays the Add Reference dialog box.
Select Advantage.Data.Provider and click Select.
Click OK to close the Add Reference dialog box.