0% found this document useful (0 votes)
71 views4 pages

Part - 1 Introduction To

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 4

What is ADO.NET?

ADO stands for Microsoft ActiveX Data Objects. ADO.NET is one of Microsoft’s Data
Access Technologies using which we can communicate with different data sources. It is
a part of the .NET Framework which is used to establish a connection between the .NET
Application and data sources. The Data Sources can be SQL Server, Oracle, MySQL,
and XML, MSAccess, MSExcel, etc. ADO.NET consists of a set of classes that can be
used to connect, retrieve, insert, update and delete data (i.e. performing CRUD
operation) from data sources. ADO.NET mainly
uses System.Data.dll and System.Xml.dll.

What types of Applications use ADO.NET?


ADO.NET can be used to develop any type of .NET application. The following are some of
the .NET applications where you can use ADO.NET Data Access Technology to interact
with a data source.
1. ASP.NET Web Form Applications
2. Windows Applications
3. ASP.NET MVC Application
4. Console Applications
5. ASP.NET Web API Applications
6. ASP.NET Core Applications
7. WPF, WCF, etc.

Components of ADO.NET
Connection, Command, DataReader, DataAdapter, DataSet, and DataView are the
components of ADO.NET that are used to perform database operations. ADO.NET has two
main components that are used for accessing and manipulating data. They are as follows:
1. Data Provider (Connected Oriented Architecture)
2. DataSet (Dis-Connected Oriented Architecture)

What are .NET Data Providers?


The Database cannot directly execute our C# Code, it only understands SQL. So, if a .NET
application needs to retrieve data or to do some insert, update, and delete operations from
or to a database, then the .NET application needs to
1. Connect to the Database
2. Prepare an SQL Command
3. Execute the Command
4. Retrieve the results and display them in the application
And this is possible with the help of .NET Data Providers.

ADO.NET Code to Connect to SQL Server Database


The following image shows the sample ADO.NET code which is connecting to SQL Server
Database and retrieves data. If you notice in the below image, here, we are using some
predefined classes such
as SQLConnection, SQLCommand, and SQLDataReader. These classes are
called .NET Provider classes and these classes are responsible for interacting with the
database and performing the CRUD operation. If you further notice all the classes are
prefixed with the word SQL, it means these classes are going to interact with only the SQL
Server database.

All these classes are present in System.Data.SqlClient namespace. We can also say that
the .NET data provider for the SQL Server database is System.Data.SqlClient.

ADO.NET Code to connect to Oracle Database


The following code is for connecting to Oracle Database and retrieve data. If you notice,
here we are using OracleConnection, OracleCommand, and OracleDataReader classes.
That means all these classes have prefixed the word Oracle and these classes are used to
communicate with the Oracle database only.
All the above classes are present in System.Data.OracleClient namespace. So, we can
say that the .NET Data Provider for Oracle is System.Data.OracleClient.

Note: Similarly, if you want to communicate with OLEDB data sources such


as MSExcel, MSAccess, etc. then you need to
use OleDbConnection, OleDbCommand, and OleDbDataReader classes. So, the .NET
Data Provider for OLEDB data sources is System.Data.OleDb.

Different .NET Data Providers

ADO.NET Data Providers


Please have a look at the following image to understand the ADO.NET Data Providers in a
better manner. As you can see, we have divided the diagram into three sections. The first
section is the .NET Applications, the second section is the .NET Data Providers and the
third section is the data sources. Based on the data source, you need to use the
appropriate provider in your application.

The point that you need to remember is depending on the provider, the ADO.NET objects
(Connection, Command, DataReader, and DataAdapter) have a different prefix as
shown below.
1. Connection – SQLConnection, OracleConnection, OleDbConnection,
OdbcConnection, etc.
2. Command – SQLCommand, OracleCommand, OleDbCommand, OdbcCommand,
etc.
3. DataReader – SQLDataReader, OracleDataReader, OleDbDataReader,
OdbcDataReader, etc.
4. DataAdapter – SQLDataAdapter, OracleDataAdapter, OleDbDataAdapter,
OdbcDataAdapter, etc.

DataSet:
The DataSet object in ADO.NET is not Provider-Specific. Once you connect to a database,
execute the command, and retrieve the data into the .NET application. The data can then
be stored in a DataSet and work independently of the database. So, it is used to access
data independently from any data source. The DataSet contains a collection of one or more
DataTable objects.

You might also like