0% found this document useful (0 votes)
20 views

UNIT 4 - ADO.NET

vb.net
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

UNIT 4 - ADO.NET

vb.net
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

ADO.

NET
UNIT -4

Mrs.K.Muthu Lakshmi
Assistant Professor
Department of Information Technology
Introduction to Ado.Net
• Ado stands for Active Database Object
• Before Ado.net we use Ado to access data from database.
Basically Ado has automatic driver detection technique
and its has only one drawback that it only provide a
connected environment so efficiency system may
decrease.
• ADO.NET is a new database technology used by .Net
platform (introduced in 2o02).
• In fact it is a set of classes used to communicate between
an application front end and a database.
• It support both connected & disconnect mode of data
access.
Difference between ADO and ADO.NET
ADO ADO.NET
It is a COM based library. It is a CLR based library.
Classic ADO require active connection ADO.NET architecture works while the
With the data store. data store is disconnected.
Locking feature is available. Locking feature is not available.
Data is stored in Binary format. Data is stored in XML format.
XML integration is not possible. XML integration is possible.
It uses the object named Recordset to It uses the Dataset object for data access
reference data from the data store. and representation.
Firewall might prevent execution of ADO.NET has firewall proof and its
classic ADO. execution will never be interrupted.
Classic ADO architecture includes client ADO.NET architecture doesn’t include
side cursor and server side cursor. such cursor.
Namespaces used in ADO.Net
• System.Data
It contains the common classes for connecting, fetching data from
database. Classes are like as Data Table , Dataset , Dataview etc.
• System.Data.SqlClient
It contain classes for connecting fetching data from Sql server database.
Classes are like as SqlDataAdapter , SqlDataReader etc.
• System.Data.OracleClient
It contain classes for connecting fetching data from Oracle database.
Classes are like as OracleDataAdapter , OracleDataReader etc.
• System.Data.OleDb
It contain classes for connecting , fetching data from any database (like
Ms Access , db2 , Oracle , Sqlserver , mySql). Classes are like as
OleDbDataAdapter , OleDbDataReader , etc.
ADO.NET Architecture
Component of ADO.NET
• The two key components of ADO.NET are
 Data Providers
 DataSet
DataSet
• Basically it is a small Data structure that may contain multiple
datatables from multiple sources.
• The information in dataset is created inform of XML and is
stored with .xsd extention .
• It support disconnected mode of data access . It has both
Scrolling mode means forward and backward scrolling
mode(fetching of data).
• DataSet can have multiple Database is able to read only single
Database.
Creating and using a DataSet
• The typing steps in creating and using a Dataset are:
 (i ) Create a DataSet object.
 (ii) Connect to a database.
 (iii) Fill the DataSet with one or more tables or
views.
 (iv) Disconnect from the database.
 (v) Use the DataSet in the application.
Data Provider
• Data provider is a set of ADO.Net classes that allow us to
access a database. Basically, it is a bridge between our
application (we can say front-end) and data source.
There are following Data provider:
 Sqlserver Data Provider :- It is used to access data from
sqlserver database (for version 7.0 or later).
 Oracle Data Provider:- It is used to access data from
oracle database (for version 8i or later).
 OleDb Data Provider:- It is used to access data from any
database (msaccess , mysql , db2).
Odbc Data Provider:- It is used to access data from any
database (msaccess).
• The four objects from the .Net Framework provides
the functionality of Data Providers in the ADO.NET.
They are
 connection Object.
 command Object.
 Data Reader Object.
 Data Adapter Object.
The SQL Connection Object
• The Connection :- The Connection object which
provides a connection to the database.
Sqlconnection con= new Sqlconnection{
“Data source=(local);
Initial Catalog=Emp;
Integrated seurity=sspi”);
• There are four connection string Parameter Name:
 Data Source Data source Identifiers the server and it could be local
machine domain name, or IP Address.
 Initial Catalog Database name.
 Integrated Security Integrated Security set to SSPI to make
connection with user’s windows login
• User ID Name of user configured in SQL Server.
• Password Password matching SQL Server User ID.

The Following shows a connection string the User ID and Password


parameter:
Sqlconnection conn =new Sqlconnection{
“Data source=DatabaseServer;
Initial Catalog=Northwind;
User ID=YourUserID;
Password=YourPassword”};
Command Object
• The command :- The command object which is used
to execute a command.
• It provide three methods which are used to execute
commands on the database:
 ExecuteNonQuery: Executes commands that have no return
values such as INSERT, UPDATE Or DELETE.
 ExecuteScalar: Returns a single value from a database
query.
 ExecuteReader: Return a result set by way of a DataReader
object.
Data Adapter Object
• Data Adapter : The DataAdapter server as a bridge between a
DataSet and data source for retrieving and saving data.
• The DataAdapter provides this bridge by using Fill to load
data from the data source into the DataSet and using Update to
send changes made in the DataSet back to the data source.
• The data adapter objects connect a command object to a
Dataset object.
• They provide the means for the exchange of data between the
data store and the tables in the DataSet.
• An OleDataAdapter object is used with an OLE-DB provider a
SqlDataAdapter object uses Tabular Data services with MS
SQL Server.
Data Reader Object
• The DataReader:- The DataReader object which
provides a forward-only, read only, connected
recordset.
• Limitations of the DataReader
• There is not possible to sort ,filter, or manipulate the data
while using a DataReader, since it is read-only and forward-
only.
Difference between DataSet and DataReader
DataSet DataReader
DataSet object can contain multiple DataReader provides forward-only and
rowsets from the same data source as well read-only access to data.
as from the relationships between them.
DataSet is a disconnected architecture. DataReader is connected architecture.
DataSet can persist data. DataReader can not persist data.
A Data is well suited for data that needs to It has live connection while reading data.
be retrieved from multiple tables.
DataSet is slower than DataReader, Due to Speed performance is better in
overhead. DataReader.

You might also like