Introduction to ADO.NET

Database is an important part of software development. In dot net, ADO.NET is the key component for developing database application. ADO.NET (ActiveX Data Objects) is the collections of classes for develop the database application.

ADO.NET supports connected and disconnected architecture. The Disconnected classes provide the core functionality for the ADO.NET Framework. In disconnected environment there is no need to continue connection with database. Data are retrieves from the database, performs updation without a constant connection to the database, and again stores the updated data back to database.

In contrast, connected environment requires a continue connection to transfer data between the client application and the data source. Connection Oriented architecture is achieved by the use of Connection, Command and DataReader object.

Important classes of ADO.NET

  • Connection
  • Command
  • Datareader
  • DataAdapter
  • Dataset
The .Net Framework provides three important Data Providers for ADO.NET. They are the Microsoft SQL Server Data Provider, OLEDB Data Provider and ODBC Data Provider.
Connection, Command, DataReader, and DataAdapter objects are data provider.
If you are using MS SQL server as a database, then use System.Data.SqlClient.
If you are using Oracle server as a database, then use System.Data. OracleClient.

Disconnected Classes


dataset

DataSet and DataReader are two main objects of ADO.NET. DataSet object supports the disconnected architecture and DataReader provides connected architecture.
You can consider DataSet as a mini Database. DataSet is collection of DataTable. A dataset can contain more than one table as in normal relational database. You can create relationship between tables. Again table is collection of DataRow and DataColumn.
DataReader works in connected environment. DataReader works fast comapare to DataSet. It is a readonly and forward only object.

ADO.NET Namespaces

The following are the important namespaces related with ADO.NET

System.Data.
This namespace is the core of ADO.NET framework. DataSet is the most import class of this namespace. It also contains classes to represent tables, columns, rows, relation and the constraint.

System.Data.Common
As its name suggests, it provides common classes, those works as base class. These classes are used by all data providers. Examples are DbConnection and DbDataAdapter

System.Data.OleDb
It provides classes that work with OLE-DB data sources using the .NET OleDb data provider. If you are using the Microsoft Access as a database, then System.Data.OleDb namespace will be used.

Example of these classes are as follows:
  • OleDbConnection
  • OleDbCommand
System.Data.Odbc
This namespace defines classes that work with the ODBC data sources using the .NET ODBC data provider. It is collection of classes used to access an ODBC data source. It contains classes such as
  • OdbcConnection
  • OdbcCommand
  • OdbcDataReader
System.Data.SqlClient
It defines the data provider for the SQL Server database. It contains classes that are used to access a SQL Server database. Examples are:
  • SqlConnection
  • SqlCommand
  • SqlDataReader
System.Data.SqlTypes
This namespace provides classes for specific data types for the SQL Server database.

Difference between ADO and ADO.NET

ADOADO.NET
It supports connection oriented architecture.Supportd connected and disconnected architecture.
It has Recordset object.It has DataSet and DataReader object
Limited support of XMLFull support of XML
Only one tableIt can contain more than one table.
Data is stored in binary format.Data is stored in XML.
You cannot send multiple transactions using a single connection instance.You can send multiple transactions using a single connection instance.