Professional Documents
Culture Documents
ADO.NET
Contents
Introduction ADO.NET
The Connection Object
The Command Object
Reading Data with the DataReader
Working with Disconnected Data - The DataSet and
DataAdapter
Adding Parameters to Commands
Using Stored Procedures
Introduction ADO.NET
ADO:- Active Data Objects.
The primary data access technology to connect into a
database from .NET is ADO.NET.
ADO.NET use for (01) connect to a database (02)
manipulate the data.
ADO.NET has support for XML(Extensible Markup Language)
data representation.
Introduction ADO.NET
ADO.NET was built for Online or Connected mode and
offline or disconnected mode.
connected Method
When you are making use of the connected layer, your code base will
explicitly connect to and disconnect from the underlying data store.
When you are using ADO.NET in this manner, you interact with the
data store using connection objects, command objects, and data
reader objects.
Introduction ADO.NET
disconnected Method
The disconnected layer, allows you to obtain a set of DataTable objects
(contained within a DataSet) that functions as a client-side copy of the
external data.
When you obtain a DataSet using a related data adapter object, the
connection is automatically opened and closed on your behalf.
This approach helps quickly free up connections for other callers.
The client receives a DataSet, it is able manipulate the contents without
cost of network .
If the client wishes to submit the changes back to the data store, the data
adapter (in conjunction with a set of SQL statements) is used once again to
update the data source, at which point the connection is closed immediately.
Data Providers
The data provider is used to interact between the
database and your program.
Function of the Data Provider:
Connecting to the database
Retrieving data from the database
Updating the data in the database
Deleting the data in the database,
Other functions .
Data Providers
Calling base class of Data provider in your program.
using System.Data.OleDb;
using System.Data.ODBC;
using System.Data.SqlClient;
Data Providers
Four key classes are used as a part of the data provider (xxx
mean Data provider name)
xxxConnection
xxxCommand
xxxDataReader
xxxDataAdapter
As you can see, conn is created in the same way that other
objects are created.
After execution
After it is executed, myDataReader will contain the results of the
command that you assigned.
This result will most likely be a set of records from the database.
You can now loop through these records by calling the Read method
of the DataReader.
Each time you call the Read method, the next record is read.
You can access the values in each record by getting their values with
a Getxxx method.
To use most of these methods, you must know the data type of the
information you are retrieving.
If you dont know the type, you will want to use the GetValue
method.
After execution
Final Coding
Summary
Connection
Command
Data reader
Get the value