UNIT 3
UNIT 3
Unit – 3 (ADO.Net)
What is C#:
ADO.NET is a module of .Net Framework which is used to
establish connection between application and data sources. Data sources can be
such as SQL Server and XML. ADO.NET consists of classes that can be used to
connect, retrieve, insert and delete data.
ADO is the acronym for ActiveX Data Objects. It allows us to connect
to underlying data or databases. It has classes and methods to retrieve and
manipulate data.
ADO.NET provides a bridge between the front end controls and the
back end database. The ADO.NET objects encapsulate all the data access
operations and the controls interact with these objects to display data, thus hiding
the details of movement of data
The following are a few of the .NET applications that use ADO.NET to connect
to a database, execute commands and retrieve data from the database.
ASP.NET Web Applications.
Windows Applications.
Other Applications.
1. Maintainability: -
ADO.NET is built around the idea of separation of data logic
and user interface. It means that we can create our application in independent
layers. Use N-tier application logic across additional tiers to maintain several user
requests at a time
2. Programmability: -
It is a programming style in which user words are used to
construct statements or evaluate expressions. For example: If we want to select
the “Marks” column from “Kawal” from the “Student” table, the following is the
way to do so. Strongly typed data and easy to write code because Microsoft Visual
Studio .NET framework provides statement completion.
3. Performance: -
It uses disconnected data architecture which is easy to scale as
it reduces the load on the database. Everything is handled on the client-side, so it
improves performance. High performance due to connected mode.
4. Scalability: -
It means meeting the needs of the growing number of clients,
which degrading performance. As it uses disconnected data access, applications
do not retain database lock connections for a longer time. Thus, it accommodates
scalability by encouraging programmers to conserve limited resources and allow
users to access data simultaneously.
ADO.NET Architecture:
ADO.net architecture, we use a two-tier model to create a bridge between .net
and the backend database, through which applications can access various types
of data using the same methodology and connect to a SQL Server database using
a different set of classes.
Types of Architecture:
Ado.net is both connection-oriented as well as disconnection oriented.
Depending upon the functionality of an application, we can make it connection-
oriented or disconnection oriented. We can even use both the modes together in
a single application.
1. Connected Architecture
2. Disconnected Architecture (Connectionless)
1. Connection Mode: -
As the name suggests, connected architecture refers to the fact that the
connection is established for the full time between the database and application.
For e.g. we make a program in C# that is connected with the database for the full
time, so that will be connected architecture.
Connected architecture is forward only and read-only. This means the connected
mode will work only in one particular direction i.e. forward and that too for read-
only purpose. Application issues query then read back results and process them.
For connected architecture, we mainly use the object of the DataReader class.
DataReader is used to retrieve the data from the database and it also ensures that
the connection is maintained for the complete interval of time.
In connected architecture, the application is directly linked with the Database
ADO.NET Components:
The ADO.NET DataSet is the core component of the disconnected architecture
of ADO.NET. The DataSet is explicitly designed for data access independent of
any data source. As a result it can be used with multiple and differing data
sources, used with XML data, or used to manage data local to the application.
The DataSet contains a collection of one or more DataTable objects made up of
rows and columns of data, as well as primary key, foreign key, constraint, and
relation information about the data in the DataTable objects
1. Connection
2. Command
3. DataReader
4. DataAdapter
1. Connection:
The Connection object provides connectivity to a data source. The Connection
object contains all of the information required to open a connection to the
database
2. Command:
The Command object enables access to database commands to return data,
modify data, run stored procedures, and send or retrieve parameter information.
Command objects provide three methods that are used to execute commands on
the database: “ExecuteNonQuery” Executes commands that have no return values
such as INSERT, UPDATE or DELETE
3. Data Reader:
The DataReader provides a high-performance stream of data from the data
source. The DataReader can provide rows of data directly to application logic
when you do not need to keep the data cached in memory. Because only one row
is in memory at a time, the DataReader provides the lowest overhead in terms of
Methods Description
Data Adapter:
The DataAdapter provides the bridge between the DataSet object and the data
source. The DataAdapter uses Command objects to execute SQL commands at
the data source to both load the DataSet with data, and reconcile changes made
to the data in the DataSet back to the data source. The DataAdapter provides four
properties that represent database commands: SelectCommand InsertCommand
DeleteCommand UpdateCommand You can write .NET Framework data
providers for any data source. The .NET Framework ships with two .NET
Framework data providers: the .NET Framework Data Provider for SQL Server
and the .NET Framework Data Provider for OLE DB
As you start working data adapters, you need take a Quick looks at data adapter
properties and methods. The DataAdapter has properties of type Command,
which represent the ways it can query, insert, delete, and update the database.
Data Adapter Properties:
These properties are of type OleDbCommand.
PROPERTY DESCRIPTION
Data Gridview :
Data GridView is a control used to display data in tables on a web page. It
displays data in both rows and columns, where each column represents a field,
and each row represents a record
GridView helps to perform key activities like Insert, Delete, Sorting, and Paging.
The DataGridView control provides a powerful and flexible way to display data
in a tabular format. You can use the DataGridView control to show read-only
views of a small amount of data, or you can scale it to show editable views of
very large sets of data
Data Gridview Property:
Property Description
AccessibilityObject Gets the AccessibleObject assigned to the
control.
AllowUserToDeleteRows Gets or sets a value indicating whether the user is
allowed to delete rows from the DataGridView.
AllowUserToOrderColum Gets or sets a value indicating whether manual
ns column repositioning is enabled.
AutoGenerateColumns Gets or sets a value indicating whether columns
are created automatically when
the DataSource or DataMember properties are
set.
AutoSize This property is not relevant for this class.
BackColor Gets or sets the background color for the control.
BackgroundColor Gets or sets the background color of
the DataGridView.
BackgroundImage Gets or sets the background image displayed in
the control.
BackgroundImageLayout Gets or sets the background image layout as
defined in the ImageLayout enumeration.
BorderStyle Gets or sets the border style for
the DataGridView
CausesValidation Gets or sets a value indicating whether the
control causes validation to be performed on any
controls that require validation when it receives
focus.