databases and data access introduction to ado.net ado.net objects adp.net namespaces differences...
TRANSCRIPT
Databases and Data Access
Introduction to ADO.NET ADO.NET objects ADP.NET namespaces Differences between ADO and ADO.NET
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++
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
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.
Data access namespaces
System.Data System.Data.OleDb System.Data.SQLClient System.Data.SQLTypes System.Data.XML
Main objects of ADO.NET
OleDbConnection / SQLConnection OleDbCommand / SQLCommand OleDbDataReader / SQLDataReader OleDbDataAdapter / SQLDataAdapter OleDbParameter / SQLParameter DataSet DataTable DataView DataRow DataColumn
SQL Managed Provider
SQL ServerDatabase
ADO.NET OverviewManaged Providers
ADO.NET Managed Provider
ADO Managed Provider
OLE DB Provider
Database
Your Application
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
ADO.NET objects
These objects are divided into two groups
To manage data (DataSet,DataTable,DataRow,DataRelation)
To connect data(Connections,DataReader)
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.
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.
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
ADO.NET Classes DataSet
DataSet
DataTable
DataRelation
DataRow
DataColumn
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
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
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
The data Source Interaction
Web pageConnection objectcommandDataReader
Data Store
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
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
ExecuteReader returns rows ExecuteNonQuery doesn’t ExecuteScalar returns single value
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
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
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
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
Conclusion
Database Theory and History Relational Database Concepts and Terminology ADO.NET Overview ADO.NET Classes
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
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
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