1 introduction to ado.net microsoft ado.net 2.0 step by step rebecca m riordan microsoft press, 2006
TRANSCRIPT
![Page 1: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/1.jpg)
1
Introduction to ADO.NET
Microsoft ADO.NET 2.0 Step by StepRebecca M RiordanMicrosoft Press, 2006
![Page 2: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/2.jpg)
2
Introduction to ADO.NET
“Active Data Objects”
A set of class defintions included in the .NET Framework
Objects collaborate to provide .NET applications (relatively) easy access to databases.
Designed for scalability. 100’s or 1000’s of clients on a database
server Offload functionality from server to client
![Page 3: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/3.jpg)
3
The ADO.NET Object Model
Adapter
Command
Reader
Connection
DataSetD
A
T
A
B
A
S
E
C
L
I
E
N
T
Data Provider
ADO.NET
Handles communication with a physical data store.
The actual data
Knows how to do SQL commands on the database
A light weight object for sequential read-only access to a query result.
Provides general disconnected access to data
http://msdn.microsoft.com/en-us/library/a6cd7c08.aspx
![Page 4: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/4.jpg)
4
Data Provider
Collection of Class Definitions Specific to a data source
MS SQL Server Oracle (others)
Same set of classes for each data source Class name differs
SqlDataConnection vs OracleDataConnection SqlCommand vs OracleCommand etc.
![Page 5: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/5.jpg)
5
Data Provider Objects
Connection Controls communication with data
source Properties:
ConnectionString Identifies server and database User ID and password (if external)
Methods Open Close
![Page 6: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/6.jpg)
6
Connection String
MS SQL Server Examples
connStr = "server=scorpius.eng.usf.edu; User ID=turnerr; Password=xxxxxxx"
connStr = "server=mssql06.discountasp.net; database=DB_110074;
User ID=rollinsturn; Password=xxxxx"
connStr = "server=(local)\\VSDOTNET; database=Bulk_Mail_Addresses; Trusted_Connection=yes";
![Page 7: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/7.jpg)
7
Data Provider Objects
Command Object Knows how to execute a SQL command on a server
Properties: CommandText
A SQL statement to be executed at the data source. SqlCommand1.CommandText = "SELECT * FROM Address_List"; Can be changed by the program.
Methods ExecuteReader ExecuteScalar ExecuteNonquery
![Page 8: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/8.jpg)
8
Data Provider Objects
DataReader
A fast, low-overhead object, similar to a StreamReader for file input.
Provides forward-only, read-only stream of data from a data source
Created by calling the ExecuteReader method of a Command object Never with “new”
Connection must remain open while the DataReader is used.
![Page 9: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/9.jpg)
9
Data Provider Objects
There are two kinds of “Adapters”
Data Adapter Present in ADO 1.0 Continued in ADO 2.1
Table Adapter New in ADO 2.0
![Page 10: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/10.jpg)
10
DataAdapter
Provides access to a collection of data from a data source Pemits client to close connection while
processing the data. Effectively provides a local cache Client accesses the cache rather than the
actual database.
Actual database can be updated when desired.
![Page 11: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/11.jpg)
11
Table Adapter
Includes a DataAdapter and a Connection object.
Improves functionality and ease of use of the original DataAdapter.
![Page 12: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/12.jpg)
12
Data Provider Objects
DataAdapter
Contains four Command Objects: SelectCommand UpdateCommand InsertCommand DeleteCommand
Uses SelectCommand to fill a DataSet Uses other command objects to
transmit changes back to the data source
![Page 13: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/13.jpg)
13
The DataSet
In-memory copy of data
No connection to a database. No knowledge of source or destination
of that data that it contains.
Simple form of relational database Has a collection of tables Has a collection of DataRelations
![Page 14: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/14.jpg)
14
The DataSet
From ADO.NET 2.0 Step by Step
![Page 15: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/15.jpg)
15
The DataSet
The DataTable Columns
Like the column defintions from a SQL CREATE TABLE statement
Name, Data Type, Max Length, Allows Nulls
Rows The data
Constraints Foreign Key Unique
![Page 16: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/16.jpg)
16
The DataSet
Data Relation
Programmatic interface for navigating from a master row in one table to related rows in another.
Example: Order ID in an Invoice to matching Order IDs in all Line Items for that invoice.
Does not enforce referential integrity A foreign key constraint does that.
![Page 17: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/17.jpg)
17
The DataSet
A DataSet object can exist independently of any database.
We will only use DataSets to hold data retrieved from a database.
![Page 18: 1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006](https://reader036.vdocuments.site/reader036/viewer/2022062314/56649ec65503460f94bd1072/html5/thumbnails/18.jpg)
18
Summary
DataAdapter
Command
DataReader
Connection
DataSetD
A
T
A
B
A
S
E
C
L
I
E
N
T
Data Provider
ADO.NET