Introduction to ADO.NET - XML

Programmers worldwide have been creating applications that access data from a database. One of the technologies that an application uses to interact with a database is ActiveX Data Object (ADO). ADO is an easy-to-use data access method that is based on COM. Microsoft combined the features of ADO with the .NET Framework to develop a technology called ADO.NET.

ADO.NET is a data access model that distributed applications use to communicate with data sources such as Microsoft SQL Server and Oracle. Using ADO.NET, you can develop high performance scalable applications that can interact with a database. In addition, the applications that use ADO.NET are based on the .NET Framework; therefore, they are interoperable across platforms.

ADO.NET allows you to access or modify the data in a database. To dothis, the application first needs to connect to a database. After a connection is established, you can make changes to the data in the database. Because ADO.NET is based on the .NET Framework, you can use the classes provided in the .NET base class library. These classes include OleDbConnection, SqlDbConnection, and so on.

Advantages of ADO.NET

As discussed earlier, ADO.NET offers you an easy and efficient way to create applications that access data from a data source. The following list discusses the advantages of the ADO.NET technology:

  • Allows the creation of high-performance applications. ADO.NET uses XML to transfer data between a data source and an ASP.NET application. This implies that the receiving application can easily interpret and understand the data that is transferred. In addition, when data is transferred using XML, the receiving application does not need to convert data types, as in the case of transferring data by using ADO. This improves the performance of the applications that use ADO.NET.
  • Allows the creation of applications with easy programming. .NET provides you with several components, classes, and commands that allow easy and quick programming. This significantly reduces the effort required to develop applications. In addition, by using the debugging tools of .NET, you can reduce the number of errors in the application.
  • Allows the creation of scalable applications. ADO.NET uses a disconnected architecture to allow multiple users to access the same application. In the disconnected architecture, the locks on the database are not retained very long. As soon as a user finishes working on a database, the lock on the database is released. This enables multiple users to access a database simultaneously.
  • Allows the creation of interoperable applications. ADO.NET uses XML to transfer data. Therefore, any application that can understand XML can read the data that is transferred using XML. This enables you to create interoperable applications by using ADO.NET. In addition, ADO.NET applications can be created in any of the .NET languages.

Architecture of ADO.NET

ADO.NET applications consist of at least two components:

  • Datasets
  • Data providers

The architecture of the ADO.NET applications is shown in Figure.

The Architecture of the ADO.NET Applications.

The Architecture of the ADO.NET Applications.

We will now discuss these components in detail.


A dataset is a memory cache object that provides a relational view of the data from a data source, such as a database. To create a dataset, you can use the DataSet class, which in turn uses the DataTable class to store the tables within the dataset. The data in a dataset is stored in XML format.

A dataset is a virtual database that is used in disconnected data architecture. When an application accesses or modifies data in a database, the data is first stored in the dataset. This is because in disconnected architecture, the application cannot access the data after modifying each row. Therefore, the data needs to be stored in a temporary memory cache, which is a dataset. The application can then access the data from the dataset.

Components of a Dataset

You can use a DataSet object to store data from one or more tables in a database, the relationships between the tables, and the constraints and keys defined for the tables in the database.

These form the components of the DataSet object, as discussed in the following list:

  • DataTableCollection. The DataTableCollection object represents the set of Data Table objects that contains one or more tables from a data source. The DataTable Collection object is represented by the DataTable Collection class. This class contains several methods that you can use to work with DataTableCollection objects. For example, you can add or remove a specific DataTable object from the DataTable Collection class by using the Add() and Remove() methods, respectively.
  • DataRowCollection. A table consists of rows and columns. All rows in the Data Table object, represented by the DataRow object, constitute the DataRowCollection object.
  • DataColumnCollection. The columns in a DataTable object, represented by a DataColumn object, are contained in the DataColumnCollection object.
  • DataRelationCollection. A DataTable object might contain one or more tables. The DataRelation object represents the relationship between the columns of the tables in the DataTable object. The DataRelationCollection object is a collection of DataRelation objects in a dataset.
  • ConstraintCollection. You can create a constraint, such as a unique key or a foreign key, for a data table. These constraints are stored in the ConstraintCollection object. The components of a DataSet object are shown in Figure.

The Components of the DataSet Object.

The Components of the DataSet Object.

Types of Datasets

Having discussed the components of the dataset, we'll next discuss the types of DataSet objects.

  • Typed datasets. You can inherit classes from the DataSet class. These classes are called typed datasets and are created using the information stored in XML schema. A typed dataset class inherits all the methods, events, and properties of the dataset class from which it is derived. Using typed datasets in an application reduces the time taken to access a column or a table. In addition, the typed dataset classes allow you to create applications with minimum errors and are used to perform data manipulation and data binding.
  • Untyped datasets. The datasets that are not created with reference to the information in the XML schema are called untyped datasets. Unlike typed datasets, untyped datasets are not classes, but they do provide you with the functionality of a dataset. To create an untyped dataset, you need to create an instance of the DataSet class in a form or a component.

Data Providers

Data providers are used to provide access to data in a database. To do this, data providers allow you to establish a connection with the data source, execute commands, and retrieve results.

Data providers contain several methods that allow you to connect to a database, retrieve data from the database, and update changes to the database. ADO.NET supports several data providers, such as Microsoft Jet OLE DB Provider, Microsoft OLE DB Provider for Oracle, Microsoft OLE DB Provider for SQL Server, and so on.

A data provider has four components, as discussed in the following list:

  • The Connection object. To access data from a database, you first need to connect to the database. To do this, ADO.NET provides you with the Connection object that establishes and manages a connection with the database.
  • The DataReader object. To read data in a sequential manner from a database, you need to use the DataReader object. The data from the database is read in the form of a data stream. The DataReader object allows only one row to be stored in the memory at any point of time. This results in more efficient performance of the application and reduction in the system overheads.
  • The DataAdapter object. This object is used to transfer data between a data source and a dataset. When you need to update the data in a database, the changes are first stored in the dataset and are then replicated to the database. Therefore, the DataAdapter object is used to communicate between the data source and the dataset.
  • The Command object. After establishing a connection with the database, you can use the Command object to perform operations such as modifying the records in the database. This object is used when there is a connection with the database. Having discussed the components of an ADO.NET application, we will now create a simple application that uses these components.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

XML Topics