What Is ADO.NET?
ADO.NET is a set of classes, included with the .NET Framework, that represents the primary method by which .NET applications interact with relational databases and other
All classes included with ADO.NET appear in the
System.Data
namespace; other subordinate namespaces provide derived classes geared toward specific database platforms. For instance, the
System.Data.SqlClient
namespace targets SQL Server databases, while
System.Data.OracleClient
focuses on Oracle RDBMS systems. Other database providers can develop streamlined
ADO.NET implements a
disconnected
data experience. In traditional database programming,
ADO.NET encourages you to open data connections just long enough to get the data that fulfills your immediate needs. Once you have the data, you drop the connection until the
SELECT * FROM Customer WHERE BalanceDue > 0 you have a choice of (1) scanning through all the records once in a quick and simple manner; and (2) loading the data into an in-memory table-like object, closing the connection, and working with the loaded records as if they were the original. If you use the first method, you can take your sweet time waltzing through the records, taking many minutes to process each one. But this type of selfish behavior is frowned upon by ADO.NET. The goal is to get in and get out as quickly as you can.
Because of the disconnected nature of ADO.NET, some techniques common in database applications need to change. For instance, the long-term locking of database records during a
|
Overview of ADO.NET
ADO.NET divides its world into two hemispheres:
providers
and the
DataSet
. Imagine your kitchen as the world of ADO.NET, with your refrigerator representing the provider, and the oven/
To use your oven, you select content from the long-term storage of the refrigerator, update it by mixing, heating, and rearranging the content, and eventually return it to the refrigerator where it will again sit in storage. This analogy isn't perfect; in fact, something just doesn't smell right about it. But it conveys the basic idea: Providers give you access to stored data, some of which can be moved into and
Providers
Large database systems, such as SQL Server and Oracle, are stand-alone "servers" (hence the "SQL
Server
"
Back in the early 1990s, Microsoft implemented ODBC (based on other existing standards) as a common system through which clients would connect to database servers, as well as other simpler data sources. Clients no longer had to worry about all of the networking protocols needed to talk with a database; all of that code was included in the ODBC driver. Microsoft later released a similar data connection system called OLE DB , based on ActiveX technology. OLE DB drivers for common systems soon appeared, although you could still get to ODBC resources through a generic ODBC driver built in OLE DB.
In .NET, both ODBC and OLE DB are
Four primary objects make up the programmer's view of the provider.
Using these objects is a little involved, but not hard to understand. To connect to a typical relational database, such as SQL Server, and process data, follow these steps:
Although the .NET Framework includes data providers for a few different data systems, the remainder of this chapter's discussion focuses only on the SQL Server provider, exposed through the System.Data.SqlClient namespace.
Note
SQL Server 2005 includes support for a new feature called "User Instances," for use with SQL Server 2005 Express Edition databases. This feature allows a low-privilege user to access a specific SQL Server Express database file without the need for an administrator to establish SQL Server security settings for that
DataSets
If you are going to do more than just quickly scan the data that comes back from a
DataReader
query, you will probably use a
DataSet
to store, manage, and
Three main objects make up the world of DataSets .
Although data sets are most often used with providers, you can use them independently to build your own in-memory collection of tables and relationships. This is similar to the "client-side record sets" that you could build with pre-.NET ADO objects, although the features included with ADO.NET make the DataSet much more powerful than the older Recordset .
Note Visual Basic 2005 includes "Typed DataSets," a feature used to integrate a DataSet with a specific data or record format. You may find them useful in your applications, but I won't be discussing them in this book. |

Expert One-on-One Visual Basic 2005 Design and Development

Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (O'Reilly))

Microsoft Visual Basic 2005 Step by Step (Step by Step (Microsoft))

Beginning VB 2005 Databases: From Novice to Professional (Beginning: From Novice to Professional)