Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

9
Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development

Transcript of Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

Page 1: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

Overview of ADO.NET

Chapter 1

ADO.NET 4.0 Development

Page 2: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

2

Contents

What is ADO.NET? The evolution of ADO to ADO.NET SQL Server data provider OLE DB data provider ODBC data provider Oracle data provider Type mappings

Page 3: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

3

What is ADO.NET?

Microsoft's database API for the Internet era• Core classes are in System.Data namespace

Four data providers supported• SQL Server data provider• OLE DB data provider• ODBC data provider• Oracle data provider

There are 3 usage styles in ADO.NET• ADO.NET connected model • ADO.NET disconnected model • LINQ to SQL and/or ADO.NET Entity Framework

Page 4: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

4

The Evolution of ADO to ADO.NET

ADO.NET is significantly different than ADO• To improve flexibility, scalability, and performance

The following diagram shows how objects in ADO map to equivalent objects in ADO.NET

Connection XxxConnection

Command XxxCommand

RecordSet XxxDataReader

DataSet

XxxDataAdapter

ADO ADO.NET

Page 5: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

5

SQL Server Data Provider

Optimised access to SQL Server 7.0 upwards, and for the Microsoft Data Engine (MSDE)• Uses lightweight Tabular Data Stream (TDS) protocol to

communicate efficiently with SQL Server

Use the System.Data.SqlClient namespace, which includes the following classes: • SqlConnection (connect to database)• SqlCommand (execute SQL statement/stored proc)• SqlDataReader (fast forward-only cursor over data)• SqlDataAdapter (useful in disconnected apps)

Page 6: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

6

OLE DB Data Provider

Access to data sources that have an OLEDB data provider, such as SQL Server 6.5 and Access• Uses native OLE DB and COM interoperability to connect

and communicate with a data source

Use the System.Data.OleDb namespace, which includes the following classes:• OleDbConnection (connect to database)• OleDbCommand (execute SQL cmd/stored proc)• OleDbDataReader (fast forward-only cursor)• OleDbDataAdapter (useful in disconnected apps)

Page 7: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

7

ODBC Data Provider

Access to data sources that have an ODBC driver• Only use this approach as a last resort!

Use the System.Data.Odbc namespace, which includes the following classes:• OdbcConnection (connect to database)• OdbcCommand (execute SQL cmd/stored proc)• OdbcDataReader (fast forward-only cursor)• OdbcDataAdapter (useful in disconnected apps)

Page 8: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

8

Oracle Data Provider

Optimized and targeted access to Oracle data sources• Introduced in the .NET Framework v1.1 (in v1.0, you have

to use the OLE DB data provider instead)

Use the System.Data.OracleClient namespace, which includes the following classes:• OracleConnection (connect to database)• OracleCommand (execute SQL cmd/stored proc)• OracleDataReader (fast forward-only cursor)• OracleDataAdapter (useful in disconnected apps)

Page 9: Overview of ADO.NET Chapter 1 ADO.NET 4.0 Development.

9

Type Mappings

Each data provider defines its own data mappings• Database data types CLR data types

Example• Commonly-used type mappings for the SQL Server data

provider:SQL Server data types CLR data types

int System.Int32

decimal, numeric, money, smallmoney System.Decimal

float System.Double

bit System.Boolean

char, varchar, nchar, nvarchar System.String, System.Char[]

date, datetime, smalldatetime System.DateTime

timestamp, binary, varbinary System.Byte[]