Beruflich Dokumente
Kultur Dokumente
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.NET and the .NET Framework
Base Classes
ADO.NET
System.Data
Managed Providers
System.Data 1/2
DataSet Tables
DataTable DataView
DataRow(s)
Relations DataColumn
DataTable
System.Data—DataSet 1/3
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; depends on:
The query/result set
Whether DataTables and Relations exist
Designed to be disconnected from the data source
Connect, execute query, disconnect
XML used to read and write data and schema
System.Data—DataSet 2/3
Collections are used to add & remove tables & relations
Properties of Interest:
Tables: Returns the collection of DataTable objects
Relations: Returns the collection of DataRelations
XML: Gets or sets the definition of the DataSet as XML
XMLData: Gets or sets the DataSet’s data as XML
XMLSchema: Gets or sets the DataSet schema as XML
Namespace: Gets or sets the namespace of the DataSet
Using Properties Sample:
aTableCollection=aDS.Tables.Add(aTable);
System.Data—DataSet 3/3
childCol);
// Add the relation to the DataSet...
ds.Relations.Add( dr );
System.Data—DataSet and XML
DataSet can read/write XML for its data and/or schema
Means: You can create or modify a DataSet using XML!
XML-related DataSet methods for reading:
ReadXml: Reads an XML schema and data into the DataSet
ReadXmlData: Reads XML data into the DataSet
ReadXmlSchema: Reads an XML schema into the DataSet
And for writing: WriteXml, WriteXmlData, WriteXmlSchema
XML-related properties:
Xml, XmlData, XmlSchema, and Namespace
DiffGrams
Methods of Reading and Writing XML
// Code for creating the DataSet mds and loading the
// DataSet from a data source not shown.
// Bind to UI element(s)...
DataGrid myGrid = new DataGrid();
myGrid.SetDataBinding( view1, “Customer”);
//...
System.Data—DataSetView
Similar to a DataView but DataSet oriented
Used to create multiple views on a DataSet
Ability to automatically set filters on the tables
Properties of Interest:
TableSettings: Gets/sets the view settings on tables
DataSet: Gets or Sets the DataSet to be viewed
System.Data—DataSetView Sample
Creating DataSetView object using a DataSet
// Create the views...
DataSetView dsView1 = new DataSetView( myDS );
// Bind to a UI element/control...
DataSet, DataRelation, Data…Views
DataSet Tables
DataView
DataTable
DataSetView
DataRow(s)
TableSettings
DataColumn
Relations TableSetting
Constraint(s)
DataRelation TableSetting
DataRelation DataTable
DataTable
ADO.NET and Managed Providers
A collection of classes for accessing data sources:
Microsoft SQL Server™ 2000, SQL Server 7, and MSDE
Any OLE Database (OLE DB) providers
Including: Oracle, JET, and SQL OLE DB Providers
Establish connection between DataSets and data stores
Two managed providers:
ADO: via the System.Data.ADO namespace
SQL Server: via the System.Data.SQL namespace
System.Data.ADO is the ADO.NET managed provider
System.Data—Managed Providers
System.Data
.SQL .ADO
SQLCommand ADOCommand
SQLConnection ADOConnection
SQLDataReader ADODataReader
SQLDataSetCommand ADODataSetCommand
Properties of Interest:
FieldCount: Returns the number of fields in the result set
HasMoreRows: Indicates if there are more rows to retrieve
RowFetchCount: Number of rows to retrieve at one time
HasMoreResults: Indicates that more results exist
Methods to retrieve data:
By column type and index: GetString, GetInt32, and so on
Read: Advances reader to next record
ADODataReader Sample
// Code for creating the ADOConnection “adoConn” not shown
String myQuery = “SELECT * FROM Customers”;
adoConn.Open();
ADOCommand myCmd = new ADOCommand( myQuery,adoConn );
IIS
Web
SystemFramework
Common.Data
BusinessFacade
BusinessRules
DataAccess
ADO.NE
T Database
Common Components
Duwamish7.Common
Contains systems configuration options
Contains common data definitions (classes)
Namespace Duwamish.Common.Data
"Internal" data representation for Book, Category,
Customer, OrderData
Duwamish7.SystemFramework
Diagnostics utilities
Pre and post condition checking classes
Dynamic configuration
In short:
Everything that's pure tech and not business code
Duwamish7.DataAccess
Contains all database-related code
Uses ADO.NET architecture
Using SQL Server managed provider
Shows DataSet, DataSetCommand usage
Optimized for performance by using stored procs
Duwamish7.BusinessRules
Implements all business rules
Validation of business objects (for example,
Customer EMail)
Updating business objects
Calculations (Shipping Cost, Taxes)
All data access performed through DataAccess
Duwamish7.BusinessFacade
Implements logical business subsystems
CustomerSystem: Profile management
OrderSystem: Order management
ProductSystem: Catalog
Reads data through DataAccess
Data validated and updated using BusinessRules
BusinessFacade encapsulates all business-related
functionality
Duwamish7.Web
Implements the user interface for Web access
Uses ASP.NET architecture
Employs Web Forms model
Uses code behind forms
Manages state
Uses custom Web Controls
All functionality accessed through BusinessFacade
Shop at Duwamish Online.NET
Demo: Duwamish in Action