Professional Documents
Culture Documents
Day3+-+ADO NET
Day3+-+ADO NET
Day3+-+ADO NET
NET
Objectives
Introduce Microsoft® ADO.NET
Show the evolution of ADO to ADO.NET
Introduce the primary components of ADO.NET
Contents
Differences Between ADO and ADO.NET
Benefits of ADO.NET
ADO.NET Core Concepts and Architecture
The ADO.NET Object Model
The DataSet and Data Views
Managed Providers
ADO vs. ADO.NET
ADO
Designed for connected access
Tied to the physical data model
The RecordSet is the central data container
RecordSet is one (1) table that contains all the data
Retrieving data from > 1 table or source requires a database JOIN
Data is “flattened”: lose relationships; navigation is sequential
Data types are bound to COM/COM+ data types
Data sharing via COM marshalling
Problems marshalling through firewalls (DCOM, binary)
ADO vs. ADO.NET
ADO.NET
Designed for disconnected access
Can model data logically!
The DataSet replaces the RecordSet
DataSet can contain multiple tables
Retrieving data from > 1 table or source does not require a JOIN
Relationships are preserved: navigation is relational
No data type conversions required
XML, like HTML, is plaintext: “Firewall friendly”
ADO.NET Goals
New applications have become loosely coupled
based on the Web application model
Disconnected data architecture,
Tight integration with XML,
Common data representation with the ability to
combine data from multiple and varied data
sources.
Optimized facilities for interacting with a database,
all native to the .NET Framework.
ADO.NET and the .NET Framework
Base Classes
Client (Console,Win,Web)
DataSet
Connection Managed
Provider
Data Source
System.Data Namespace
DataSet Tables
DataTable DataView
DataRow(s)
Relations DataColumn
DataTable
Working Data - The DataSet
An in-memory cache of data from a data source
Common way to represent and manipulate data
Universal data container
Not just for use with databases
Logical or physical representation of data
Designed to be disconnected from the data source
Connect, execute query, disconnect
Can use XML
To read and write data
To read and write XMLSchema
XML and the DataSet
DataSet can read/write XML for its data and/or schema
You can create or modify data in a DataSet using XML
You can create or modify the DataSets schema using XML
XML-related DataSet methods for reading:
ReadXml: Reads an XML schema and data into the DataSet
ReadXmlSchema: Reads an XML schema into the DataSet
And for writing:
WriteXml, WriteXmlSchema
Namespace property: sets the namespace for serialization
.NET Data Providers Hierarchy
.Common
Contains classes
shared by both
System.Data
.SqlClient .OleDb
SqlCommand OleDbCommand
SqlConnection OleDbConnection
SqlDataReader OleDbDataReader
SqlDataAdapter OleDbDataAdapter
OleDbConnection and SqlConnection
Represent a unique session with a data source
Create, open, close a connection to a data source
Functionality and methods to perform transactions
OleDbConnection example:
String conStr="Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=NWIND_RW.MDB";
OleDbConnection aConn = new OleDbConnection(conStr);
aConn.Open();
// Execute Queries using OleDbDataAdapter Class
aConn.Close();
OleDbDataAdapter Class
Maintainability
Separation of data logic and user interface
Summary
ADO.NET is the evolution of ADO
It is a disconnected, Web-centric model
Flexible in its ability to work with data
Increases your ability to logically organize data
Extensive support for XML
Facilitates working with and sharing data
Interacts with a wide variety of data sources