|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
Data processing has traditionally relied primarily on a connection-based, two-tier model. As data processing increasingly uses multitier architectures, programmers are switching to a disconnected approach to provide better scalability for their applications.
There are two components of ADO.NET that you can use to access and manipulate data:
.NET Framework data providers
.NET Framework Data Providers
The .NET Framework Data Providers are components that have been explicitly designed for data manipulation and fast, forward-only, read-only access to data. The Connection object provides connectivity to a data source. The Command object enables access to database commands to return data, modify data, run stored procedures, and send or retrieve parameter information. The DataReader provides a high-performance stream of data from the data source. Finally, the provides the bridge between the DataSet object and the data source. The DataAdapter uses Command objects to execute SQL commands at the data source to both load the DataSet with data, and reconcile changes made to the data in the DataSet back to the data source.
The ADO.NET DataSet is explicitly designed for data access independent of any data source. As a result, it can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application. The DataSet contains a collection of one or more objects made up of rows and columns of data, as well as primary key, foreign key, constraint, and relation information about the data in the DataTable objects.
The following diagram illustrates the relationship between a .NET Framework data provider and a DataSet.
Choosing a DataReader or a DataSet
When deciding whether your application should use a DataReader (see Retrieving Data Using the DataReader) or a DataSet (see Using DataSets in ADO.NET), you should consider the type of functionality that your application requires. Use a DataSet to do the following:
Cache data locally in your application so that you can manipulate it. If you only need to read the results of a query, the DataReader is the better choice.
Remote data between tiers or from an XML Web service.
Interact with data dynamically such as binding to a Windows Forms control or combining and relating data from multiple sources.
Perform extensive processing on data without requiring an open connection to the data source, which frees the connection to be used by other clients.
If you do not require the functionality provided by the DataSet, you can improve the performance of your application by using the DataReader to return your data in a forward-only, read-only fashion. Although the DataAdapter uses the DataReader to fill the contents of a DataSet (see Populating a DataSet from a DataAdapter), by using the DataReader you can boost performance because you will save memory that would be consumed by the DataSet, as well as avoid the processing required to create and fill the contents of the DataSet.
XML and ADO.NET
ADO.NET leverages the power of XML to provide disconnected access to data. ADO.NET was designed hand-in-hand with the XML classes in the .NET Framework; both are components of a single architecture.
ADO.NET and the XML classes in the .NET Framework converge in the DataSet object. The DataSet can be populated with data from an XML source, whether it is a file or an XML stream. The DataSet can be written as World-Wide Web Consortium (W3C) compliant XML, including its schema as XML Schema definition language (XSD) schema, regardless of the source of the data in the DataSet. Because of the native serialization format of the DataSet is XML, it is an excellent medium for moving data between tiers, making the DataSet an optimal choice for remoting data and schema context to and from an XML Web service.
ADO.NET Platform Requirements
The Microsoft .NET Framework SDK (including ADO.NET) is supported on Microsoft® Windows XP, Windows 2000, Windows NT 4 with Service Pack 6a, Windows Millennium Edition, Windows 98, and Windows CE.
The .NET Framework Data Provider for OLE DB and the .NET Framework Data Provider for ODBC requires MDAC 2.6 or later, and MDAC 2.8 Service Pack 1 (SP1) is recommended. You can download MDAC 2.8 SP1 from the Data Access and Storage Developer Center.
The following code example shows how to include thenamespace in your applications, in order to use ADO.NET:
The ADO.NET classes are found in System.Data.dll, and are integrated with the XML classes found in System.Xml.dll. When compiling code that uses the System.Data namespace, reference both System.Data.dll and System.Xml.dll. For an example of an ADO.NET application, see.
Remoting or Marshaling Data Between Tiers and Clients
The design of the DataSet enables you to easily transport data to clients over the Web using XML Web services, as well as allowing you to marshal data between .NET components using .NET remoting services. You can also remote a strongly typed DataSet in this fashion. For an overview of XML Web services, see. For an example of consuming a DataSet from an XML Web service, see .
For an overview of remoting services, see. Note that in ADO.NET 2.0, DataTable objects can also be used with both remoting services and XML Web services.