Ado

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

ADO.

NET presentation
INTRODUCTION
ADO stands for Microsoft ActiveX Data Objects
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, etc.
 ADO.NET consists of classes that can be used to connect,
retrieve, insert and delete data.
 ADO.NET mainly uses System.Data.dll and System.Xml.dll.
COMPONENTS OF ADO.NET
Components are designed for data manipulation and faster
data access. 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 and
2. DataSet.
WHAT IS .NET DATA
PROVIDERS?
The Database can not 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
WHAT IS .NET DATA
PROVIDERS?
we are using some classes such as
SQLConnection
SQLCommand
SQLDataReader
SQLDataAdapter

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.
DATASET

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.
ADO.NET SQLCONNECTION
The ADO.NET SqlConnection class belongs to
System.Data.SqlClient namespace and is used to establish
an open connection to the SQL Server database.

 The most important point that you need to remember is


the connection does not close implicitly even it goes out
of scope.

The connections should be opened as late as possible, and


SQL COMMAND CLASS
The ADO.NET SqlCommand class in C# is used to store and
execute the SQL statement against the SQL Server database.
Methods of SqlCommand Class
 BeginExecuteNonQuery() - This method initiates the
asynchronous execution of the Transact-SQL statement or
stored procedure that is described by this
System.Data.SqlClient.SqlCommand.
Cancel() - This method tries to cancel the execution of a
System.Data.SqlClient.SqlCommand.
Clone() - This method creates a new
SQL COMMAND CLASS
CreateParameter() - This method creates a new instance of a
System.Data.SqlClient.SqlParameter object
ExecuteReader() - This method Sends the
System.Data.SqlClient.SqlCommand.CommandText to the
System.Data.SqlClient.SqlCommand.Connection and builds a
System.Data.SqlClient.SqlDataReader.
ExecuteScalar() - Executes the query, and returns the first
column of the first row in the result
set returned by the query. Additional columns or rows are ignored.
SQL COMMAND CLASS
ExecuteNonQuery() - This method executes a Transact-SQL
statement against the connection and returns the number of
rows affected.

Prepare() - This method creates a prepared version of the


command on an instance of SQL Server.

ResetCommandTimeout() - This method resets the


CommandTimeout property to its default value.
ADO.NET SQLDATAREADER
•The ADO.NET SqlDataReader class in C# is used to read data
from the SQL Server database in the most efficient manner.
•It reads data in the forward-only direction. It means, once it
read a record, it will then read the next record, there is no way
to go back and read the previous record.
•The SqlDataReader is connection-oriented. It means it requires
an open or active connection to the data source while reading
the data.
•The data is available as long as the connection with the
database exists
ADO.NET SQLDATAADAPTER
 The ADO.NET SqlDataAdapter in C# works as a
bridge between a DataSet and a data source (SQL
Server Database) to retrieve data.

 The SqlDataAdapter is a class that represents a set


of SQL commands and a database connection.

 It can be used to fill the DataSet and update the


data source.
Fill() Method
 It opens the connection to the database, executes the SQL
command, fills the dataset and data tables with the data, and
closes the connection.

 This method handles the Opening and Closing of the database


connections automatically for us. The connection is kept open
only as long as it is needed.

 That means once the Fill method completes its execution, then
the connection closes automatically.

 Once the dataset or data table is filled, then no active


THANK YOU

You might also like