A Guided Garden Stroll through the .NET Framework Class Library
Namespace: SYSTEM.DATA
● I am the Data Namespace. Whole books have been written about me, and there’s more to come. Anyone who programs .NET applications using an external database will be using this namespace. That is, unless your particular application requires specific record locking and other fine database control. (Expect these details to be addressed in an upcoming release of the .NET framework!).
The most important thing to remember about how I am organized lies in the fact that, for mostly platform portability reasons, I am divided into two main classifications. One part deals mostly with connecting, updating, inserting and retrieving data from particular databases, and the other mostly deals with managing the data after it’s been pulled from a particular data source.
If you think of this latter case in terms of a fully functional in-memory database that is totally agnostic of the actual source of the data, then you will be absolutely on track with how System.Data works.
System.Data consists mostly of these in-memory database elements. The DataSet is the main class in System.Data. The DataSet can include one or many DataTables. The DataSet can also define many DataRelation objects that define the relationships between tables in the DataSet.
In System.Data, there are also classes you can use to define constraints on DataColumns including the UniqueConstraint and ForeignKeyConstraint.
There is also a DataView object in System.Data that you can use for sorting, filtering, searching and editing your in-memory database.
The DataTable class contains a collection of DataRow objects that represent each row in the table as well as a collection of DataColumn objects which represent and define all of the table’s columns.
Use the System.Data.Isolation data type enumeration in a Connection.BeginTransaction method call to define what degree your database connection should isolation transactions. These members include "Chaos", "ReadCommitted", "RepeatbleRead", etc. types of isolation levels.
There are also several events and exceptions defined in this namespace which can be used for monitoring error conditions or determining when data is updated, for example.
The System.Data.Common namespace includes two classes that you should be familiar with. These are the DataAdapter, which is used as a bridge to link the database specific classes with the database agnostic classes. The DataAdapter.Fill method, is one method used to cause a data connection to be established to an external database, retrieve data and load the in-memory DataSet and close the connection, all in one method call.
Use the DataTableMapping object when you want to have multiple tables in your DataSet filled when your stored procedures or SQL Statements retrieve multiple result-sets in one call.
Use the System.Data.SqlClient namespace when connecting to SQL Server, use the newly released System.Data.OraClient namespace when connecting to an Oracle database, and use System.Data.OleDB when connecting to other databases that have an OleDB provider.
Within the database specific namespaces, such as SqlClient and OraClient, there are other classes that are quite useful. One such class is the DataReader which is a high-speed, read-only mechanism for pulling data. It is important to note that as long as a DataReader can actively get data, it must maintain an open connection to your database. Especially in scaleable distributed applications, too many open connections can be a bad thing, so be sure to manually close your connections when using the DataReader before dropping your reference to this object.