1. Chapter-5 Outline
♣Overview of ActiveX Data Objects
♣C# Data Access Features
♣Relational Database Concepts
♣Using ADO Data Control to Access Data
♣Structured Query Language (SQL)
♣Manipulating Data
♣Using the Data Form Wizard
2. Databases
store information in records, fields, and tables
Database management system (DBMS): computer programs used
to manage and query databases
Example DBMSs include SQL server, Oracle, and Access
Many DBMSs store data in tabular format
Data in tables are related through common data field keys
Uses a query language to program database access
Structured query language (SQL)
ActiveX Data Objects (ADO.NET): .NET data access technology
for accessing data in databases
3. Database Connectivity
Database connection is a facility that allows client software to communicate
with database server software, whether on the same machine or not.
Connection is required to send commands and receive answers.
Database driver is a piece of software for accessing a database.
There are various DB and language specific database drivers.
For C# there are alternative ways to connect to a database(different data
access technologies):
ODBC (Open DB Connectivity) – older open standard, works with C, C++,
C#, and Visual Basic languages
ADO.NET - .NET data access technology, sit on the top of ODBC
JDBC (Java Database Connectivity) works with Java
4. ADO .NET
ADO- Stands for ActiveX Data Object.NET
It is a data access technology that is primarily disconnected manner and
designed to provide efficient and scalable data access
Database table(s) can be retrieved to a temporary file
Used for DB connections and offers to perform DB manipulations like
insertion, deletion, updating, retrieving etc.
Includes number of classes that can be used to retrieve, manipulate, and
update data in databases
Implements a disconnected data access model
In this model data connections are established and left open only long
enough to perform the requested action.
Example: if an application requests data from a db, the connection opens
just long enough to load the data into the application and then it closes.
5. Cont.….
To retrieve data, first you must connect to the DB
It uses data providers to connect, execute commands, and retrieve
results from a database
ADO.NET provides an architecture for communicating between
an application & data source.
“data source” can be anything that has the required API, but
usually it is a DB server
Data
Source
Connection
Object
(ADO.Net)
Data Adaptor Dataset
(Local)
Application
Architecture:
6. Data Providers
Classes are encapsulated into a different namespace by provider
Four core classes make up each data provider namespace
Connection
Command
DataReader
DataAdapter
8. ADO .NET Namespace
Namespaces Description
System.Data
Contains the definition for columns, relations, tables,
database, rows, views and constraints.
System.Data.Sql
Client
Contains the classes that used to connect to a Microsoft
SQL Server database such as SqlCommand, SqlConnection,
SqlDataAdapter.
System.Data.Odb
c
Contains classes required to connect to most ODBC
drivers. These classes include
OdbcCommand,OdbcConnection.
System.Data.Or
acleClient
Contains classes such as
OracleConnection,OracleCommand required to connect to
an Oracle database.
9. ADO .NET DatabaseTransactions
A. Query Processing
Retrieves the data from the backend database with a select statement into
frontend application
Query (select) statement will be written in the frontend application and it will
be sent to the backend database
That statement will be executed at backend
Result will be returned to frontend application
B. Non-Query Processing
Doesn’t retrieves any data from database
The process of modifying the table’s data
Eg. Insertion, Deletion, Updation, Creating a table, Dropping a table, Altering a table
C. Stored Procedure/ Function Handling
Executes a stored procedure/ a stored function, that is already created at
backend
Connecting with database
10. Advanced Query Processing
Query processing is of two types:
1. Standard Query Processing
Implemented with DataReader buffer
2. Advanced Query Processing
Implemented with DataSet, DataTable, DataRow buffers
DataAdapter: sends SQL statement and executes it at backend
DataSet: holds data that is received from database, after execution
- can hold multiple/array of table’s data at-a-time
DataTable: holds a single table, from the DataSet
DataRow: holds a single row, from the DataTable
12. Cont.….
1. Data Set
oStores data from the database on the local machine
oRepresents a subset of the database
oIt is disconnected, in memory representation of data
- to update the database a reconnection is required
oData can be loaded to a data set from any valid data source such
as SQL Server db, MS-Access db, My SQL db or xml
oDataset object contains: DataTable objects and DataRelation objects
- DataTable is defined by data Columns, data Rows and Constraints,
- DataRelations: allows you to create associations between
rows in one table and rows in another table.
16. Cont.….
Properties Description
CaseSensitive Indicates whether string comparisons within the
data tables are case-sensitive.
Container Gets the container for the component.
DataSetName Gets or sets the name of the current data set.
DefaultViewManager Returns a view of data in the data set.
DesignMode Indicates whether the component is currently in
design mode.
EnforceConstraints Indicates whether constraint rules are followed
when attempting any update operation.
Events Gets the list of event handlers that are attached to
this component.
17. Cont.….
Properties Description
ExtendedProperties Gets the collection of customized user information
associated with the DataSet.
HasErrors Indicates if there are any errors.
IsInitialized Indicates whether the DataSet is initialized.
Locale Gets or sets the locale information used to compare
strings within the table.
Namespace Gets or sets the namespace of the DataSet.
Prefix Gets or sets an XML prefix that aliases the
namespace of the DataSet.
Relations Returns the collection of DataRelation objects.
Tables Returns the collection of DataTable objects.