Jahan University
Vice Chancellor Office
Computer Science Faculty
Database/ Network Department
Visual
Programming-I
Introduction to ADO.NET
Program: 6th Semester
Due Date : 30-10-24
By: DrSerat
• Introduction to ADO.NET
• Architecture Of ADO.NET
• Components of ADO.NET
Outline
• Data Provider
• Connection Class
• Command and the Parameter Classes
• Data Adapter Class
• Data Reader Class
3
Introduction to ADO.NET
oActiveX Data Object “ADO.NET” is a set of classes that represent
data access services to the Microsoft .NET programmer.
oADO.NET provides a rich set of components for creating distributed,
data sharing applications.
oIt is an essential part of the Microsoft .NET Framework, providing
access to relational, XML, and application data.
4
Introduction to ADO.NET
oADO.NET supports a variety of development needs, including the
creation of front-end database applications, tools, languages, or
Internet browsers.
oAll ADO.NET classes are located at the System.Data namespace with
two files named System.Data.dll and System.Xml.dll.
5
Introduction to ADO.NET
oBasically, ADO.NET provides a set of classes to support you to develop
database applications and enable you to connect to a data source to
retrieve, manipulate, and update data with your database.
o These classes can be divided into the following three major components:
Data Provider
Data Set
Data Table
6
Introduction to ADO.NET
o The DataSet and the DataTable classes are located at the System.Data namespace.
o The Data Provider classes are located at the different namespaces based on the types of the Data
Providers.
o Data Provider contains four classes: Connection, Command, DataAdapter, and DataReader.
Connection object: set a connection between project and source.
Command object: execute, retrieve and manipulate data.
DataAdapter object: move data between DataSet and database.
DataReader object: Perform data queries from the database (read - only).
7
Introduction to ADO.NET
oThe DataSet class can be considered as a table container, and it can contain
multiple data tables. These data tables are only a mapping to those real
data tables in your database.
oThe DataSet and DataTable classes have no direct relationship with the Data
Provider class; therefore, they are often called Data Provider - independent
components.
oFour classes, such as Connection, Command, DataAdapter, and DataReader,
that belong to Data Provider are often called Data Provider - dependent
components. 8
ARCHITECTURE OF ADO.NET
oThe ADO.NET architecture can be divided into two logical parts:
Command execution
Caching.
oCommand execution requires features like connectivity, execution, and reading
of results.
oCaching of results is handled by the DataSet.
9
ARCHITECTURE OF ADO.NET
o This is typically called “ filling the DataSet. ” Figure 1 shows a typical architecture of
ADO.NET.
o The data tables are embedded into the DataSet as a DataTable-Collection, and the
data transactions between the DataSet and the Data Provider, such as SELECT,
INSERT, UPDATE, and DELETE, are made by using the DataAdapter via its own four
different methods:
o SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand,
respectively.
o The Connection object is only used to set a connection
10
ARCHITECTURE OF ADO.NET
11
COMPONENTS OF ADO.NET
oADO.NET is composed of three major components:
Data Provider
DataSet
DataTable.
12
COMPONENTS OF ADO.NET/Data Provider
o The Data Provider can also be called a data driver, and it can be used as a major
component for your data driven applications.
o The functionalities of the Data Provider is as following:
Connect your data source with your applications.
Execute different methods to perform the associated data query and data
accessing operations between your data source and your applications.
Disconnect the data source when the data operations are done.
13
COMPONENTS OF ADO.NET/Data Provider
oData Provider can have several versions, and each version is
matched to each kind of database.
oThe popular versions of the Data Provider are:
Open Data Base Connectivity ( Odbc ) Data Provider (ODBC.NET)
Object Linking and Embedding Data Base ( OleDb ) Data Provider
(OLEDB.NET)
SQL Server ( Sql ) Data Provider (SQL Server.NET)
Oracle ( Oracle ) Data Provider (Oracle.NET)
14
The Connection Class
o Data Provider contains four subclasses, and the Connection component is one of them.
o This class provides a connection between your applications and the database you
selected to connect to your project.
o To use this class to set up a connection between your application and the desired
database, you need first to create an instance or an object based on this class.
o Depending on your applications, you can create a global connection instance for your
entire project or you can create some local connection objects for each of your form
windows.
15
The Connection Class
o Generally, a global instance is a good choice, since you do not need to perform multiple open and close
operations for connection objects.
o The connection string is a property of the Connection class, and it provides all necessary information to
connect to your data source. Regularly, this connection string contains as following:
o 1. Provider
o 2. Data Source
o 3. Database
o 4. User ID
o 5. Password
16
The Connection Class
o The parameter names in a connection string are case insensitive, but some of parameters,
such as the Password or PWD, may be case sensitive.
o If you installed a local SQL server and client such as the SQL Server 2022 Express on your
computer, the Provider should be local host.
o If you are using a remote SQL Server instance, you need to use that remote server ’s
network name.
o For the Oracle server database, you do not need to use parameter( mean local host is not
needed).
17
The Connection Class
o The Data Source parameter indicates the name of the network computer on which your
SQL server or Oracle server is installed and running.
o The Database parameter indicates your database name.
o The User ID and Password parameters are used for the security issue for your database.
o In most cases, the default Windows NT Security Authentication is utilized.
18
The Command and the Parameter Classes
o Command objects are used to execute commands against your database, such as a data
query, an action query, and even a stored procedure.
o In fact, all data accesses and data operations between your data source and your
applications are achieved by executing the Command object with a set of parameters.
o Command class can be divided into the different categories such as :
o OleDbCommand, OdbcCommand, SqlCommand, and OracleCommand
19
The Properties of the Command Class
o The Command class contains more than 10 properties, but only four of them are used
popularly in most applications:
Connection property
CommandType property
CommandText property
Parameters property
o The Connection property is used to hold a valid Connection object.
o Command object can be executed to access the connected database based on this
Connection object.
o The CommandType property is used to indicate what kind of command that is stored in
the CommandText property should be executed.
20
The Methods of the Command Class
21
The DataAdapter Class
oThe DataAdapter serves as a bridge between a DataSet and a data
source for retrieving and saving data.
oThe DataAdapter provides this bridge by mapping Fill, which
changes the data in the DataSet to match the data in the data
source, and Update, which changes the data in the data source to
match the data in the DataSet.
22
The DataReader Class
o The DataReader class is a read - only class, and it can only be used to retrieve and
hold the data rows returned from a database executing an ExecuteReader method.
o This class provides a way of reading a forward - only stream of rows from a
database.
o Depending on the Data Provider you are using, four popular DataReaders are
provided by four Data Providers.
o OdbcDataReader, OleDbDataReader, SqlDataReader, and OracleDataReader.
o To create a DataReader instance, you must call the ExecuteReader method
23
Thanks
24