0% found this document useful (0 votes)
72 views35 pages

An Introduction To ADO. Net: Prepared by Manish Kumar Aery (IM66) Department of Computer Application IET Bhaddal (Ropar)

This document provides an introduction to ADO.Net. It discusses what ADO.Net is, how it compares to ADO, and its core object structure including connections, commands, readers, and datasets. It describes how ADO.Net uses namespaces and data providers to access different data sources. Key objects like the connection, command, data reader, data adapter, and dataset are explained along with how to use them to connect to a database, execute queries, and retrieve and work with data in a disconnected manner using datasets.

Uploaded by

sandro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views35 pages

An Introduction To ADO. Net: Prepared by Manish Kumar Aery (IM66) Department of Computer Application IET Bhaddal (Ropar)

This document provides an introduction to ADO.Net. It discusses what ADO.Net is, how it compares to ADO, and its core object structure including connections, commands, readers, and datasets. It describes how ADO.Net uses namespaces and data providers to access different data sources. Key objects like the connection, command, data reader, data adapter, and dataset are explained along with how to use them to connect to a database, execute queries, and retrieve and work with data in a disconnected manner using datasets.

Uploaded by

sandro
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

An Introduction to ADO.

Net

Prepared By
Manish Kumar Aery(IM66)
Department of computer Application
IET Bhaddal (Ropar)
Contents

What is [Link]?
What happened to ADO?
The [Link] object structure
Connecting
Commanding
Readers and DataSets
What is [Link]?

 The data access classes for the .Net framework


 Designed for highly efficient data access
 Support for XML and disconnected record sets
And the .Net framework?

 A standard cross language interface


 Encapsulation of services, classes and data types
 Uses XML for data representation
Where does ADO sit?

VB C# C++ Jscript …

Common Language Specification

Visual Studio .NET


[Link] Windows Forms

[Link] [Link]

Base Class Library

Common Language Runtime (CLR)


Windows COM+ Services
ADO / [Link] Comparisons

Feature ADO [Link]


In memory Recordset object Dataset object
data storage Mimics single table Contains DataTables

Data Reads Sequential Sequential or non-


sequential

Data OLE/DB via the Managed provider


Sources Connection object calls the SQL APIs
ADO / [Link] Comparisons

Feature ADO [Link]


Disconnected Limited support, Strong support,
data suitable for R/O with updating

Passing COM marshalling DataSet support for


datasets XML passing

Scalability Limited Disconnected access


provides scalability
.NET Data Providers

SQL .NET

Data Provider
SQL SERVER

OLE DB .NET
Client Data Provider
OLE DB
Other DB
Provider

ODBC .NET ODBC


Data Provider Driver Other DB
Data Provider Functionality

Client .Net Data Provider

Connection Command
Rows
DataReader

DataSet
DataAdapter database
[Link] object model
Fill
DataAdapter DataSet
Update

UpdateCommand

DeleteCommand
SelectCommand

InsertCommand
Errors Collection

Command

Connection Parameters

Data Source
Namespaces

 [Link] & [Link]


 [Link] &
[Link]
 [Link]
 [Link] & [Link]
Using Namespaces

 [Link]
Imports [Link]
Imports [Link]
Dim sqlAdp as SqlDataAdapter
 C#
using [Link];
using [Link];
SqlDataAdapter sqlAdp= new SqlDataAdapter();
SQL Namespace Objects

 using [Link];
 SqlConnection
 SqlCommand
 SqlDataReader
 SqlDataAdapter
 SqlParameter
 SqlParameterCollection
 SqlError
 SqlErrorCollection
 SqlException
 SqlTransaction
 SqlDbType
Connecting to SQL

 using [Link];

string sConnectionString =
"Initial Catalog=Northwind;
Data Source=localhost;
Integrated Security=SSPI;";

SqlDataAdapter sqlAdp= new


SqlDataAdapter(sConnectionString);

[Link]();
[Link]();
Connection Pooling

 [Link] pools connections.


When you close a connection it is released back into a pool.
 SqlConnection conn = new SqlConnection();
[Link] =
"Integrated Security=SSPI;Initial Catalog=northwind";
[Link](); // Pool A is created.
 SqlConnection conn = new SqlConnection();
[Link] =
"Integrated Security=SSPI;Initial Catalog=pubs";
[Link]();
// Pool B is created because the connection strings differ.
 SqlConnection conn = new SqlConnection();
[Link] =
"Integrated Security=SSPI;Initial Catalog=northwind";
[Link](); // The connection string matches pool A.
Getting data

 SqlCommand
ExecuteReader
ExecuteNonQuery
ExecuteScalar
ExecuteXMLReader
 SqlDataAdapter
DataSet
Using the command object

 SqlCommand
Multiple constructors
 New()
 New(cmdText)
 New(cmdText, connection)
 New(cmdText, connection,
transaction)
Using the command object

 string sSelectQuery =
"SELECT * FROM Categories ORDER BY CategoryID";
string sConnectionString =
"Initial Catalog=Northwind;
Data Source=localhost;
Integrated Security=SSPI;";
SqlConnection objConnect = new SqlConnection(sConnectString);
SqlCommand objCommand = new SqlCommand(sSelectQuery,
objConnect);
/*
 [Link] = 15;
[Link] = [Link];
 */
[Link]();
SqlDataReader drResults;
drResults = [Link]()
[Link]();
[Link]();
Command Methods

 .ExecuteReader() - Returns DataReader


 .ExecuteNonQuery() - Returns # of Rows Affected

Returns XMLReader Object to Read


 .ExecuteXMLReader() -
XML documentation
 .ExecuteScaler() - Returns a Single Value e.g. SQL SUM
function.
The DataReader object

 DataReader objects are highly optimised for fast, forward only


enumeration of data from a data command
 A DataReader is not disconnected
The DataReader object

 Access to data is on a per record basis.


 Forward only
 Read only
 Does support multiple recordsets
Creating a data reader

SqlDataReader sqlReader;
sqlReader = [Link]();
while ([Link]())
{
// process, sqlReader("field")
}
[Link]();
Other Methods

 GetString(), GetInt() etc.


 GetSqlString(), GetSqlInt32() etc.
 GetValues()
 IsDBNull()
 GetSchemaTable()
DataSets

 In-memory representation of data contained in a database/XML


 Operations are performed on the DataSet, not the data source
 Can be created programmatically, using a DataAdapter or XML schema
and document (or any mixture)
Creating DataSets

 Setup SqlConnection
 Setup a SqlDataAdapter
 Create a DataSet
 Call the .Fill() method on the DA
DataAdapters

 Pipeline between DataSets and data sources


 Geared towards functionality rather than speed
 Disconnected by design
 Supports select, insert, delete, update commands and methods
DataAdapters

 Must always specify a select command


 All other commands can be generated or specified
Using the DataAdapter

SQLDataAdapter sqlDA =
new SqlDataAdapter();

[Link] =
new SqlCommand ("select * from
authors“, sqlConnection);

DataSet sqlDS = new


DataSet("authorsTable");
[Link](sqlDS, "authorsTable");
DataAdapters

 For speed and efficiency you should set your own InsertCommand,
UpdateCommand and DeleteCommand
 Call GetChanges to seperates the updates, adds and deletes since the
last sync. Then sync each type.
DataTables

 A DataSet contains one or more DataTables.


 Fields are held within the DataTable.
 And in DataRows, DataColumns.
Sets, Tables and Rows

DataSet
DataTable
DataTable
DataRow
DataRow
Using DataTables

With a DataTable we can


 Insert, modify and update
 Search
 Apply views
 Compare
 Clear
 Clone and Copy
DataRelations

 New to [Link]
 Tables within a DataSet can now have relationships, with integrity.
 Supports cascading updates and deletes.
DataViews

 Like a SQL view


 Single, or multiple tables
 Normally used with GUI applications via Data Binding.
Thank You!!

You might also like