0% found this document useful (0 votes)
33 views25 pages

Chapter6 Working With

Uploaded by

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

Chapter6 Working With

Uploaded by

Maanka Wiil hoog
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Application Development II

(ASP.NET)

CHAPTER8. Working With ADO


.NET

LECTURER :MOHAMED ABDI DAGANE


WORKING WITH ADO .NET
In this Chapter will cover :
Introducing ADO .NET
What Is ADO.NET?

 ADO vs ADO.net

ADO.NET Architecture components

Data Provider

CREATING CONNECTION OBJECT

OleDBCommand/ SQLCommand Classes

Browsing and Modifying Databases in Visual Studio

Running Queries in Visual Studio


INTRODUCING ADO .NET
 ADO.NET is the next generation of ActiveX Data
Objects (ADO).
 ADO.NET is the technology that .NET applications
use to interact with a database
 ADO.NET is an evolution of the ADO model for data
access.
 In terms of ASP.NET development, ADO.NET
provides the framework for accessing any type of
data for use with ASP.NET pages.
 This allows users to view or change information
stored in any kind of data warehouse.
WHAT IS ADO.NET?

ADO.NET provides a set of classes for working with


data. ADO.NET is:
• An evolutionary, more flexible successor to ADO
• A system designed for disconnected environments
• A programming model with advanced XML support
• A set of classes, interfaces, structures, and enumerations that
manage data access in the .NET Framework
ADO VS ADO.NET
 Main Differences:
ADO ADO.NET
Connection Model Connection Oriented Disconnected Model is
Model is used mostly. used: Messeage-like
Model.
Disconnected Access Provided by RecordSet Provided by
DataAdapter and
Dataset
Data Representation One Recordset for one One Dataset for many
Table interrelated tables with
relationships
Data Exchange Binary Mode – Firewall Use XML and XSD
Problem schema types are fully
supported
XML Support Limited Robust Support
ADO VS ADO.NET
 Connection Model:
ADO:
Client application needs to be connected

always to data-server while working on the
data.
These results in open connections for long time
and thus data can not be accessed in parallel.
ADO .NET
Client disconnects connection immediately the
data is processed. This will cache data at client
side to achieve better performance.
Hence ADO .net creates “disconnected version
of RecordSet object
ADO VS ADO.NET
Data Representation:
Recordset is a set of rows or record s holding data
that was typically fetched from some data store.
Recordsets are generated one per table. This does
not support hierarchical structure of data access. It
will be programmer’s responsibility to define
relationships among different recordsets.
Rercordsets can not support data accessing from
multiple sources.
Above limitations are resolved by implementation
of Dataset objects in ADO.net mode
ADO VS ADO.NET
 Data Passing:
ADO objects communicate in binary mode the Advanced
Data Table Gram (ADTG) format, to provide transmission
of data between applications. hence it will be really
difficult to pass data across firewalls.
ADO.net use text-based XML format for transmission of
or passing data
ADO.NET ARCHITECTURE
COMPONENTS
 ADO.NET relies on the functionality in a small set
of core classes. These classes can be divide into
two groups:
1.Those that are used to contain and manage data
such as DataSet, DataTable, DataRow, DataView
and DataRelation
2. And those that are used to connect to a specific
data source such as Connection, Command, and
DataReader.
DATA PROVIDER
 The sets of classes that handle connected operations are
referred to generically as data providers (managed
providers.)
 A data provider can be compared in many respects to what
we used to call a database driver.
 Each set of data interaction classes is called an ADO.NET
data provider.
 They provide all the mechanisms for connecting to,
accessing, manipulating, and retrieving information from
any OLE DB–compliant data store, such as Microsoft
Access or SQL Server.
DATA PROVIDER
 Microsoft provides two managed providers with ADO.NET: the SQL
managed provider and the OLE DB managed provider.
 The ADO.NET data provider classes include

 Connection

 Command

 DataReader

 DataAdapter
NAME IN
SYSTEM.DATA.
TYPE OF SYSTEM.DATA.
PURPOSE OLEDB
CLASS SQLC
NAMESPACE
NAMESPACE
Establishes and
manages a
Connection OleDbConnection SQLConnection
connection to a
database.
Carries out an
operation while
Command OleDbCommand SQLCommand
connected to the
database.
Presents a stream of
data
DataReader generated by a query OleDbDataReader SQLDataReader
operation
on a database.
Fetches data from a
database
DataAdapter and transfers it into a OleDbDataAdapter SQLDataAdapter
DataSet
THE ADO.NET OBJECT MODEL
DataSet

DataTable DataTable

ODBC SQL Server OLE DB .NET Oracle


Data Provider Data Provider Data Provider Data Provider

ODBC SQL Server OLEDB sources Oracle


sources 7.0 (and later) (SQL Server 6.5) sources
DATABASE INTERACTION WITH
ADO.NET
 There are five general steps to interacting with data in ASP.NET
pages:
1. Create a database connection object.
2. Open the database connection.
3. Populate a Dataset with the desired data.
4. Set up a Data View to display data.
5. Bind a server control to the DataView
DATABASE INTERACTION WITH ADO.NET
 Before you can use ADO.NET in your ASP.NET pages to talk to
databases, you have to provide specific information about the database
you’re interested in accessing.
 These important information' includes where the database is located,
what type of database it is (for example, MS Access, SQL Server, or
Oracle), what version it is, and so on.
 This information is supplied to ADO.NET using a connection string
that you build manually.
CREATING CONNECTION OBJECT
 The connection object is used to establish a connection to the
database. The leDBConnection and SQLConnection classes
are both such connection classes.
 ADO.NET you must explicitly open your connections using
one of its constructors.
CREATING CONNECTION OBJECT
 The SQLConnectionObject
SqlConnection con = New SqlConnection
("data source= (local);initial catalog=SOFA;integrated
security=true")
con.Open()
 in connection string, there are three properties commonly
used :
 Data source: This indicates the name of the server where
the data source is located. If the server is on the same
computer that hosts the ASP.NET site, localhost is
sufficient.
CREATING CONNECTION OBJECT
 Initialcatalog : This is the name of the database that this
connection will be accessing.
 Integrated security : This indicates you want to connect to SQL
Server using the Windows user account that’s running the web
page code, provided you supply a value of SSPI (which stands
for Security Support Provider Interface).
 Alternatively, you can supply a user ID and password that’s
defined in the database for SQ L Server authentication.
OLEDBCOMMAND/ SQLCOMMAND
CLASSES
 Once a connection is established, you'll need classes to interact with and
manipulate data. The classes that are the key to such interaction are the
OleDBCommand and SQLCommand, which we refer to generically as the
command classes.
 There are two properties for a command object that must be set before the
command object an be used. One is the connection to use. The other is the
SQL statement to carry out some desired operation.
sSQL = "SELECT * FROM Customers"
 Dim myCommand As New SQLCommand(sSQL, myConnection)
METHOD OF
PURPOSE
COMMAND OBJECT

Used to execute a SQL statement that does not


ExecuteNonQuery return a value. A typical example would be a
DELETE statement.
Return a reference to a DataReader object. this is
ExecuteReader an object to get fast, read-only, forward-only
access to a set of rows.
Executes a SQL statement and returns only the
first field in the first row of the result. This is
ExecuteScalar
often helpful when accessing aggregate SQL
functions such as COUNT.
Like ExecuteReader but returns rows in XML
format. This is an easy way to get XML straight
ExecuteXMLReader (only out of a SQL Server database.
available for SQLCommand
class)
BROWSING AND MODIFYING DATABASES IN VISUAL
STUDIO
 As an ASP.NET developer, you may have the responsibility of
creating the database required for the application using Visual
Studio Explorer window.
 In Server Explorer, right-click Data Connections, and then click
Add Connection.
 Configure the connection
RUNNING QUERIES IN VISUAL STUDIO
 1. Right- click your connection , and choose New Query .
 2. Choose the table (or tables) you want to use in your query from the Add
Table dialog, click Add, and then click Close .
RUNNING QUERIES IN VISUAL
STUDIO
 3 You’ll now see a handy query-building window. You can create your query
by adding check marks next to the fields you want, or you can edit the SQL
by hand in the lower portion of the window.
 4. When you’re ready to run the query, select Query Designer ➤ Exe cute
SQL from the menu.
RUNNING QUERIES IN VISUAL STUDIO
END

You might also like