ADO.net.docx
ADO.net.docx
NET
ADO.NET consists of a set of Objects that expose data access services to the .NET
environment. It is a data access technology from Microsoft .Net Framework , which provides
communication between relational and non relational systems through a common set of
components .
System.Data namespace is the core of ADO.NET and it contains classes used by all data
providers. ADO.NET is designed to be easy to use, and Visual Studio provides several wizards
and other features that you can use to generate ADO.NET data access code.
The two key components of ADO.NET are Data Providers and Data Set . The Data
Provider classes are meant to work with different kinds of data sources. They are used to perform
all data-management operations on specific databases. Data Set class provides mechanisms for
managing data when it is disconnected from the data source.
Data Providers
The .Net Framework includes mainly three Data Providers for ADO.NET. They are the
Microsoft SQL Server Data Provider , OLEDB Data Provider and ODBC Data Provider . SQL
Server uses the SqlConnection object , OLEDB uses the OleDbConnection Object and ODBC
uses OdbcConnection Object respectively.
A data provider contains Connection, Command, DataAdapter, and DataReader objects. These
four objects provides the functionality of Data Providers in the ADO.NET.
Connection
The Connection Object provides physical connection to the Data Source. Connection
object needs the necessary information to recognize the data source and to log on to it properly,
this information is provided through a connection string.
Command
The Command Object uses to perform SQL statement or stored procedure to be executed
at the Data Source. The command object provides a number of Execute methods that can be used
to perform the SQL queries in a variety of fashions.
DataReader
DataAdapter
DataAdapter Object populate a Dataset Object with results from a Data Source . It is a
special class whose purpose is to bridge the gap between the disconnected Dataset objects and
the physical data source.
DataSet
DataSet provides a disconnected representation of result sets from the Data Source, and it
is completely independent from the Data Source. Data Set provides much greater flexibility
when dealing with related Result Sets.
DataSet contains rows, columns, primary keys, constraints, and relations with other DataTable
objects. It consists of a collection of DataTable objects that you can relate to each other with
DataRelation objects. The DataAdapter Object provides a bridge between the DataSet and the
Data Source.
Uses of a DataSet
Cache data locally in your application so that you can manipulate it. If you only need to
read the results of a query, the DataReader is the better choice.
Interact with data dynamically such as binding to a Windows Forms control or combining
and relating data from multiple sources.
Perform extensive processing on data without requiring an open connection to the data
source, which frees the connection to be used by other clients.
GridView control
GridView control is a successor to the ASP.NET 1.X DataGrid control. It provides more
flexibility in displaying and working with data from your database in comparison with any other
controls. The GridView control enables you to connect to a datasource and display data is tabular
format, however you have bunch of options to customize the look and feel. When it is rendered
on the page, generally it is implemented through <table> HTML tag.
The GridView control displays the values of a data source in a table. Each column represents
a field, while each row represents a record.
Properties:
Both events occur when the page link is clicked. They fire
PageIndexChanging,
before and after GridView handles the paging operation
PageIndexChanged
respectively.
RowCancelingEdit Fires when Cancel button is clicked in Edit mode of GridView.
RowCommand Fires when a button is clicked on any row of GridView.
RowCreated Fires when a new row is created in GridView.
RowDataBound Fires when row is bound to the data in GridView.
Both events fires when Delete button of a row is clicked. They
RowDeleting,RowDeleted fire before and after GridView handles deleting operaton of the
row respectively.
Fires when a Edit button of a row is clicked but before the
RowEditing
GridView hanldes the Edit operation.
Both events fire when a update button of a row is clicked. They
RowUpdating, RowUpdated fire before and after GridView control update operation
respectively.
Both events fire when column header link is clicked. They fire
Sorting, Sorted before and after the GridView handler the Sort operation
respectively.
Example :