Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences...
-
Upload
terence-simmons -
Category
Documents
-
view
236 -
download
3
Transcript of Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences...
![Page 1: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/1.jpg)
Databases and Data Access
Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET
![Page 2: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/2.jpg)
ADO.NET OverviewLooking Back
ADO (ActiveX Data Objects) Simple component-based, object-oriented interface Provides a programming model to OLE DB accessible
outside of C++
![Page 3: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/3.jpg)
ADO.NET OverviewWhat Is ADO.NET?
ADO .NET is a collection of classes, interfaces, structures, and enumerated types that manage data access from relational data stores within the .NET Framework These collections are organized into namespaces:
System.Data, System.Data.OleDb, System.Data.SqlClient, etc.
ADO .NET is an evolution from ADO.The next generation of ADO
![Page 4: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/4.jpg)
Managed Providers
It performs operation of communicating with the database
Similar to ODBC driver or OLEDB provider ADO.NET currently provides two
distinct managed providers The SQL Server managed provider is used with SQL
server OLEDB managed provider is used to communicate
with any OLEDB compliant database like Access or Oracle.
![Page 5: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/5.jpg)
Data access namespaces
System.Data System.Data.OleDb System.Data.SQLClient System.Data.SQLTypes System.Data.XML
![Page 6: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/6.jpg)
Main objects of ADO.NET
OleDbConnection / SQLConnection OleDbCommand / SQLCommand OleDbDataReader / SQLDataReader OleDbDataAdapter / SQLDataAdapter OleDbParameter / SQLParameter DataSet DataTable DataView DataRow DataColumn
![Page 7: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/7.jpg)
SQL Managed Provider
SQL ServerDatabase
ADO.NET OverviewManaged Providers
ADO.NET Managed Provider
ADO Managed Provider
OLE DB Provider
Database
Your Application
![Page 8: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/8.jpg)
ADO.NET OverviewData Access Styles
Connected: Forward-only, read-only Application issues query then reads back results and
processes them “Firehose” cursor DataReader object
Disconnected Application issues query then retrieves and stores
results for processing Minimizes time connected to database DataSet object
![Page 9: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/9.jpg)
ADO.NET objects
These objects are divided into two groups
To manage data (DataSet,DataTable,DataRow,DataRelation)
To connect data(Connections,DataReader)
![Page 10: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/10.jpg)
What is DataSet,DataAdapter
Dataset is an in-memory disconnected
representation of data from actual database
Since dataset is totally disconnected from the
database there must be some means of
communication between the dataset and the
database
DataAdapter is used for that purpose.
![Page 11: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/11.jpg)
Functions of DataAdapter
Populate the dataset by fetching data from database
Updating changes made to the dataset back to the database
Changes made to the dataset are not written to the database unless explicitly updated
via DataAdapter.
![Page 12: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/12.jpg)
DataSet
The DataSet object stores the disconnected data
from a database and allows you to manipulate it
as a single object
The DataSet Objects inturn has two other
objects DataTable,DataRelation
![Page 13: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/13.jpg)
ADO.NET Classes DataSet
DataSet
DataTable
DataRelation
DataRow
DataColumn
![Page 14: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/14.jpg)
DataTable
It consists collection of DataRow and DataColumn
DataRow
Represents a single row of information
Individual values can be accessed using the field
names
DataColumn
Does not hold any data instead information
about the column such as Datatype,default value
![Page 15: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/15.jpg)
DataRelation
Each DataRelation Object represents a single
parent/Child relationship between two different
datasets
DataView-Used to bind data in the DataTable
object
Displays data or it can also filter and sort data
![Page 16: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/16.jpg)
ADO.NET Classes DataRelation
Relates two DataTables via DataColumns
DataType value of both DataColumns must
be identical
Updates can be cascaded to child DataTables
Modifications that invalidate the relation are
disallowed
![Page 17: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/17.jpg)
The data Source Interaction
Web pageConnection objectcommandDataReader
Data Store
![Page 18: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/18.jpg)
ADO.NET ClassesIDbConnection Interface
Creates a unique session with a data source Implemented by SqlDbConnection and OleDbConnection
Functionality Open, close connections Begin transactions
IDbTransaction provide Commit and Rollback methods
Used in conjunction with IDbCommand and IDataAdapter objects
![Page 19: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/19.jpg)
ADO.NET Classes IDbCommand Interface
Represents a statement to be sent to a data source Usually, but not necessarily SQL
Implemented by OleDbCommand and SqlCommand
Functionality Define statement to execute Execute statement Pass and retrieve parameters Create a prepared (compiled) version of command
![Page 20: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/20.jpg)
ExecuteReader returns rows ExecuteNonQuery doesn’t ExecuteScalar returns single value
![Page 21: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/21.jpg)
ADO.NET Classes System.Data.OleDb Namespace
Managed provider for use with OLEDB providers SQLOLEDB (SQL Server) – use System.Data.SQL MSDAORA (Oracle) JOLT (Jet) OLEDB for ODBC providers
OleDbConnection, OleDbCommand and OleDbDataReader classes
Classes for error handling Classes for connection pooling
![Page 22: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/22.jpg)
ADO.NET Classes DataSet
A collection of tables Has no knowledge of the source of the data Keeps track of all relationships among tables Rich programming model (has objects for tables,
columns, relationships, and so on) Remembers original and current state of data Can dynamically modify data and metadata Native serialization format is XML Located in System.Data
![Page 23: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/23.jpg)
ADO.NET Classes System.Data.SqlClient Namespace
Managed provider native to SQL Server Built on TDS (Tabular Data Stream) for high
performance in SQL Server SqlConnection, SqlCommand and SqlDataReader classes
Classes for Error handling Connection pooling (implicitly enabled by default )
System.Data.SqlTypes provides classes for native SQL Server data types
![Page 24: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/24.jpg)
ADO.NET Classes IDataAdapter Interface
Populates or sends updates to a DataSet Implemented by OleDbDataAdapter and SqlDataAdapter
Not connection based Represents an asynchronous approach A superset of a command object Contains four default command objects for
Select, Insert, Update, and Delete
![Page 25: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/25.jpg)
Conclusion
Database Theory and History Relational Database Concepts and Terminology ADO.NET Overview ADO.NET Classes
![Page 26: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/26.jpg)
AppendixADO vs. ADO.NET
ADO is a slower automation layer over OLE DB for use in Visual Basic, etc.
ADO.NET provides direct, fast access to data from any language
ADO.NET essentially has merged OLE DB and ADO into a single layer
![Page 27: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/27.jpg)
AppendixADO vs. ADO.NET
Feature ADO ADO.NETMemory-resident Data Representation
Uses RecordSet, which can contain one table
Uses DataSet, which can contain one or more tables represented by DataTables
Relationship Between Multiple Tables
Require the JOIN query Supports the DataRelation object
Data Visitation Scans RecordSet rows sequentially
Uses a navigation paradigm for non-sequential access
Disconnected Access Provided by RecordSet but typically supports connected access
Communicates with standardized calls to the DataAdapter
![Page 28: Databases and Data Access Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET.](https://reader036.fdocuments.net/reader036/viewer/2022062409/56649e9e5503460f94ba03e8/html5/thumbnails/28.jpg)
AppendixADO vs. ADO.NET
Feature ADO ADO.NETProgrammability Uses Connection object to
transmit commandsUses strongly typed programming characteristics of XML
Sharing Disconnected Data Between Tiers or Components
Uses COM marshalling to transmit disconnected Recordset
Transmits a DataSet with an XML file
Transmitting Data Through Firewalls
Problematic because firewalls are typically configured to prevent system-level requests
Supported, DataSet object use XML, which can pass through firewalls
Scalability Database locks and active database connections for long durations
Disconnected access to database data without retaining database locks