Computer Science Department Rapid Application Development: Chapter 4: Database Programming

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Computer Science Department

Rapid Application Development


Chapter 4: Database Programming
ADO NET is a data access technology from Ms .NET Framework that provides communication between
relational and non relational systems through a common set of components.

Programmers use ADO NET to access:-

a) Data
b) Data service

Applications communicate with a database to:-

i) Retrieve stored data and present in friendly way


ii) Update database by Insertng, Modifying or Deleting data

Microsoft ActiveX Data Objects.Net (ADO.Net) is a model, a part of the .Net framework that is
used by the .Net applications for retrieving, accessing, and updating data.

ADO.Net Object Model

ADO.Net object model is nothing but the structured process flow through various components. The
object model can be pictorially described as:
The data residing in a data store or database is retrieved through the data provider.

An application accesses data either through a dataset or a data reader.

o Datasets store data in a disconnected cache and the application retrieves data from it.
o Data readers provide data to the application in a read-only and forwardonly mode.

Data Provider
A data provider is used for connecting to a database, executing commands and retrieving data, storing
it in a dataset, reading the retrieved data and updating the database.

There are following different types of data providers included in ADO.Net

The .Net Framework data provider for SQL Server - provides access to Microsoft SQL
Server.
The .Net Framework data provider for OLE DB - provides access to data sources exposed
by using OLE DB.
The .Net Framework data provider for ODBC - provides access to data sources exposed by
ODBC.
The .Net Framework data provider for Oracle - provides access to Oracle data source.
The EntityClient provider - enables accessing data through Entity Data Model (EDM)
applications.

The data provider in ADO.Net consists of the following four objects:

a) Connection : This component is used to set up a connection with a data source.


b) Command : A command is a SQL statement or a stored procedure used to retrieve, insert, delete
or modify data in a data source.
c) DataReader : Data reader is used to retrieve data from a data source in a read-only and
forward-only mode.
d) DataAdapter : This is integral to the working of ADO.Net since data is transferred to and from a
database through a data adapter. It retrieves data from a database into a dataset and
updates the database. When changes are made to the dataset, the changes in the database
are actually done by the data adapter.

DataSet

DataSet is an in-memory representation of data. It is a disconnected, cached set of records that are
retrieved from a database. When a connection is established with the database, the data adapter creates
a dataset and stores data in it. After the data is retrieved and stored in a dataset, the connection with the
database is closed. This is called the 'disconnected architecture'. The dataset works as a virtual database
containing tables, rows, and columns.

The DataSet class is present in the System.Data namespace. The following table describes all the
components of DataSet:

DataTableCollection: It contains all the tables retrieved from the data source.
DataRelationCollection : It contains relationships and the links between tables in a data set.

ExtendedProperties : It contains additional information, like the SQL statement for retrieving data, time
of retrieval, etc.

DataTable: It represents a table in the DataTableCollection of a dataset. It consists of the DataRow and
DataColumn objects. The DataTable objects are casesensitive.

DataRelation : It represents a relationship in the DataRelationshipCollection of the dataset. It is used


to relate two DataTable objects to each other through the DataColumn objects.

DataRowCollection : It contains all the rows in a DataTable.

DataView : It represents a fixed customized view of a DataTable for sorting, filtering, searching, editing,
and navigation.

PrimaryKey : It represents the column that uniquely identifies a row in a DataTable.

DataRow : It represents a row in the DataTable. The DataRow object and its properties and methods
are used to retrieve, evaluate, insert, delete, and update values in the DataTable. The NewRow method is
used to create a new row and the Add method adds a row to the table.

DataColumnCollection : It represents all the columns in a DataTable.

DataColumn : It consists of the number of columns that comprise a DataTable.

Connecting to a Database
The .Net Framework provides two types of Connection classes:

SqlConnection - designed for connecting to Microsoft SQL Server.


OleDbConnection - designed for connecting to a wide range of databases, like
Microsoft Access and Oracle.

Sql Connection Example


Excel Connection Example

You might also like