Pillars of Ado.Net

by Sachin Singh


Posted on Tuesday, 22 December 2020

Tags: Pillars of Ado.Net Ado.net in nutshell

If you have gone through my previous article what is Ado.Net then you must be knowing that Ado.Net is nothing but a set of libraries. It wouldn't be wrong to say that it is a collection of some classes and in order to communicate with any data source, we just need to create the related object and call the required methods.

There are different data providers which help to interact with the different data sources for example to communicate with SQL Server we have System.Data.SqlClient and similarly for Oracle, we have System.Data.OracleClient.

Each of these data providers contains 4 main classes, which are the pillars of Ado.Net.

Connection Class

It is used to establish the connection to the corresponding Data Source. The Microsoft Ado.Net team has created this class as a Sealed class, this means it cannot be inherited by other classes. depending on the provider, the different connection classes are
    • SQLConnection: to establish an open connection to the SQL Server database.
    • OracleConnection : to establish an open connection to the Oracle database
    • OleDbConnection: to establish an open connection to the OleDb Data Source like Excel and Access.
    • OdbcConnection : to establish an open connection to the Odbc Data Source.
   

Command Class

This class is used to store and execute SQL statement for corresponding database. Like SqlConnection Class, it is also a sealed class so it also cannot be inherited by other classes. Depending on the provider , the different command classes are
    • SQLCommand: to store and execute SQL statement for SQL Server database.
    • OracleCommand : to store and execute SQL statement for the Oracle database
    • OleDbCommand:- to store and execute SQL statement for OleDb Data Source like Excel and Access.
    • OdbcCommand: to store and execute SQL statement for Odbc Data Source.

DataReader Class

This class is used to read data from the corresponding database. It reads data in a forward-only stream of rows from a SQL Server database. it is also a sealed class like SqlConnection and SqlCommand, which means it too cannot be inherited, It implements the IDisposable interface, always remember that the class that implements IDisposable interface are automatically disposed of if we use them inside using statement. Depending on the provider, the different DataReader classes are
    • SQLDataReader: to read data from SQL Server database.
    • OracleDataReader: to read data from the Oracle database
    • OleDbDataReader: to read data from OleDb Data Source like Excel and Access.
    • OdbcDataReader: to read data from Odbc Data Source.

DataAdapter Class

The DataAdapter sits between the DataSet and data sources like SQL Server and acts as a bridge between them, which opens the connection, fills the DataSet, and closes the connection. DataAdapter is a class that wraps the SqlCommand and SqlConnection, this means the DataAdapter instance needs a SqlConnection object and a Sqlcommand object. The DataAdapter is not used to fill the DataSet only but also they are capable of updating the data source, which means any changes made to DataSets could be saved into the data source with the help of DataAdapter which we will discuss in a later article. Depending on the provider , the different DataAdapter classes are
    • SQLDataAdapter: bridge between a DataSet and SQL Server database.
    • OracleDataAdapter: bridge between a DataSet and Oracle database
    • OleDbDataAdapter: bridge between a DataSet and OleDb Data Source like Excel and Access.
    • OdbcDataAdapter: bridge between a DataSet and Odbc Data Source.

we will discuss each of these one by one in upcoming articles.