MSDN Documentation

NET Concepts: Data Access

ADO.NET Overview

ADO.NET is a set of classes that expose data access services to the .NET Framework developer. ADO.NET is part of the .NET Framework, and it provides a mechanism for developers to connect to data sources, retrieve data, and store that data back into the data source, all while maintaining data integrity.

Key Components of ADO.NET

ADO.NET consists of a set of .NET Framework classes that expose data access functionality. The most important of these classes are found in the System.Data namespace. ADO.NET can be used to connect to many different data sources, including relational databases (like SQL Server, Oracle, MySQL), NoSQL databases, and even XML files.

1. Connection Objects

Connection objects represent a unique session to a data source. They are used to establish a connection to the database and are responsible for managing the connection lifecycle. Examples include:

A connection object must be opened before it can be used and closed when it is no longer needed.

2. Command Objects

Command objects are used to execute SQL statements or stored procedures against a data source. They are associated with a connection object.

Commands can be executed to return data (using ExecuteReader or ExecuteScalar) or to perform data manipulation operations (using ExecuteNonQuery).

3. DataReader Objects

DataReader objects provide a forward-only, read-only stream of data from the data source. They are the most efficient way to retrieve a large amount of data from a database when you do not need to manipulate the data in memory.

DataReader objects are created by calling the ExecuteReader method on a Command object.

4. DataSet and DataTable Objects

DataSet and DataTable objects are central to ADO.NET for working with data in memory.

These objects are useful when you need to retrieve data, manipulate it (filter, sort, update), and then send the changes back to the data source. They support caching of changes and conflict resolution.

5. DataAdapter Objects

DataAdapter objects act as a bridge between a DataSet and a data source. They are used to fill a DataSet with data from a data source and to reconcile changes made to the DataSet back to the data source.

A DataAdapter uses four commands to retrieve data and update data:

Key Features and Benefits