Vijaya Lakshmi Byri Support Engineer Developer Support, VB Webdata Microsoft Corporation
Vijaya Lakshmi Byri Support Engineer Developer Support, VB Webdata Microsoft Corporation
Vijaya Lakshmi Byri Support Engineer Developer Support, VB Webdata Microsoft Corporation
NET
2
Introduction to ADO.NET
ADO.NET is a natural evolution of ADO, built
around n-tier development and architecture,
with XML at its core.
ADO.NET is the new set of classes that
exposes data access services to the .NET
programmer.
It is an integral part of the class Framework,
which contains the entire library of classes
that Microsoft provides with .NET, including
the base classes for the primitive system
types, I/O, network, data, and XML.
3
ADO.NET Components
Managed providers
DataSets
4
Managed Provider
The .NET data provider is a set of
components including the Connection,
Command, DataReader, and DataAdapter
objects.
The .NET data provider is designed to be
lightweight, creating a minimal layer between
the data source and your code, increasing
performance while not sacrificing
functionality.
5
Managed Provider Components
6
Types of Managed Providers
OLEDB managed provider
SQL managed provider
ODBC managed provider
7
OLEDB Managed Provider
Uses native OLE DB through COM
interoperability to enable data access.
To use the OLE DB .NET data provider, you
must also use an OLE DB provider. The
following providers are compatible with
ADO.NET:
Microsoft OLE DB Provider for SQL Server
Microsoft OLE DB Provider for Oracle
Microsoft.Jet.OLEDB.4.0 OLE DB Provider for Jet
These classes are located in the
System.Data.OleDb namespace. 8
Sample OLEDB Connection
Dim OLEDBCn as OLEDBConnection
Dim strConn as string
StrConn = "Provider=MSDAORA.1;Data
Source=dseoracle8; user
id=demo;password=demo;"
10
Sample SQL Connection
Dim SQLCn as SQLConnection
Dim strConn as String
12
ODBC Managed Provider (2)
Only the following drivers have been tested
with the ODBC .NET data provider:
Microsoft SQL ODBC Driver
Microsoft ODBC Driver for Oracle
Microsoft Jet ODBC Driver
These classes are located in the
System.Data.Odbc namespace
The ODBC .NET data provider also requires
the installation of MDAC 2.6 or later
13
Sample ODBC Connection
Dim odbccn As Odbc.OdbcConnection = New
Odbc.OdbcConnection("Driver={SQL
SERVER};SERVER=Vijayab1;UID=sa;PWD=Password
1;DATABASE=Northwind;")
Dim odbcda As Odbc.OdbcDataAdapter = New
Odbc.OdbcDataAdapter("Select * from employees",
odbccn)
Dim odbcds As New DataSet()
odbcda.Fill(odbcds, "Employees")
Me.DataGrid1.DataSource =
odbcds.Tables("Employees") 14
Managed Provider Components
Command Object
15
Managed Provider Components
DataReader
16
DataReader Example
Dim SQLcn As SqlClient.SqlConnection
Dim cmd As SqlClient.SqlCommand
Dim dr As SqlClient.SqlDataReader
Dim strconn As String
dr.Close() 17
Managed Provider Components
DataAdapter
Represents a set of data commands and a
database connection which are used to fill
the DataSet and update the data source.
18
DataAdapter Properties
SelectCommand
InsertCommand
DeleteCommand
UpdateCommand
TableMappings
19
DataSet
DataSet
Tables
Table
Columns
Column
Constraints
Constraint
Rows
Row
Relations
Relation
20
DataSet Example
Dim strconn As String
da.SelectCommand = cmd
OLEDBCn.Open()
22
Differences Between ADO and
ADO.NET (2)
ADO ADO.NET
Uses server-side and client- The architecture is
side cursors disconnected so cursors
are not applicable
Database locks and active Does not retain database
database connections locks
23
When to Use ADO in .NET
Applications
Client/server applications
Server-side cursors
Pessimistic locking
24
How to Use ADO
Set a reference to Microsoft ActiveX® Data
Object 2.x library by selecting COM tab (click
Project and then References)
The ADODB object should be used
25
Using ADO in .NET
Example:
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strconn As String
Dim DA As OleDb.OleDbDataAdapter
DA = New OleDb.OleDbDataAdapter()