0% found this document useful (0 votes)
111 views7 pages

ADO.net.docx

The document discusses ADO.NET and the GridView control in ASP.NET. ADO.NET provides objects for accessing and manipulating data and includes data providers, datasets, and data adapters. It allows applications to access data sources in a disconnected manner. The GridView control displays data from a database in a customizable table and supports features like sorting, paging, editing and deleting records.

Uploaded by

bbbb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
111 views7 pages

ADO.net.docx

The document discusses ADO.NET and the GridView control in ASP.NET. ADO.NET provides objects for accessing and manipulating data and includes data providers, datasets, and data adapters. It allows applications to access data sources in a disconnected manner. The GridView control displays data from a database in a customizable table and supports features like sorting, paging, editing and deleting records.

Uploaded by

bbbb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

ADO.

NET

Data processing has traditionally relied primarily on a connection-based, two-tier model.


As data processing increasingly uses multi-tier architectures, programmers are switching to a
disconnected approach to provide better scalability for their applications.

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.

Data Providers and DataSet

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

The DataReader Object is a stream-based , forward-only, read-only retrieval of query


results from the Data Source, which do not update the data. Data Reader requires a live
connection with the database and provides a very intelligent way of consuming all or part of the
result set.

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.

 Remote data between tiers or from an XML Web service.

 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.

Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth,


Height etc. are implemented through style properites of <tahle> 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.

The GridView control supports the following features:

 Binding to data source controls, such as SqlDataSource.


 Built-in sort capabilities.
 Built-in update and delete capabilities.
 Built-in paging capabilities.
 Built-in row selection capabilities.
 Programmatic access to the GridView object model to dynamically set properties, handle
events, and so on.
 Multiple key fields.
 Multiple data fields for the hyperlink columns.
 Customizable appearance through themes and styles.

<asp:GridView ID="gridService" runat="server">


</asp:GridView>

Properties:

Behavior Properties of the GridView Control


AllowPaging true/false. Indicate whether the control should support paging.
AllowSorting true/false. Indicate whether the control should support sorting.
Gets the current sort expression (field name) that determines the
SortExpression
order of the row.
Gets the sorting direction of the column sorted currently
SortDirection
(Ascending/Descending).
Gets or sets the data source object that contains the data to
DataSource
populate the control.
DataSourceID Indicate the bound data source control to use (Generally used
when we are using SqlDataSource or AccessDataSource to bind
the data, See 1st Grid example).
true/false. Indicates whether a separate column should be added
AutoGenerateEditButton
to edit the record.
true/false. Indicates whether a separate column should be added
AutoGenerateDeleteButton
to delete the record.
true/false. Indicate whether a separate column should be added
AutoGenerateSelectButton
to selecat a particular record.
true/false. Indicate whether columns are automatically created
AutoGenerateColumns
for each field of the data source. The default is true.

Style Properties of the GridView Control

Defines the style properties for every alternate row in the


AlternatingRowStyle
GridView.
Defines the style properties for the row in EditView (When you
EditRowStyle
click Edit button for a row, the row will appear in this style).
RowStyle Defines the style properties of the rows of the GridView.
Defines the style properties of Pager of the GridView. (If
PagerStyle
AllowPaging=true, the page number row appears in this style)
Defines the style properties of the empty row, which appears if
EmptyDataRowStyle
there is no records in the data source.
Defines the style properties of the header of the GridView. (The
HeaderStyle
column header appears in this style.)
FooterStyle Defines the style properties of the footer of GridView.

Appearance Properties of the GridView Control


Indicates the space in pixel between the cells and the border of
CellPadding
the GridView.
CellSpacing Indicates the space in pixel between cells.
Both/Horizontal/Vertical/None. Indicates whether GrdiLines
GridLines
should appear or not, if yes Horizontal, Vertical or Both.
HorizontalAlign Indicates the horizontal align of the GridView.
Indicates the text to appear when there is no record in the data
EmptyDataText
source.
ShowFooter Indicates whether the footer should appear or not.
Indicates whether the header should appear or not. (The column
ShowHeader
name of the GridView)
BackImageUrl Indicates the location of the image that should display as a
background of the GridView.
Caption Gets or sets the caption of the GridView.
left/center/right. Gets or sets the horizontal position of the
CaptionAlign
GridView caption.

State Properties of GridView Control

Gets the collection of objects that represent the columns in the


Columns
GridView.
Gets or sets the 0-based index that identifies the row currently to
EditIndex
be edited.
Returns a GridViewRow object that represents the footer of the
FooterRow
GridView.
Returns a GridViewRow object that represents the header of the
HeaderRow
GridView.
Gets the number of the pages required to display the reocrds of
PageCount
the data source.
PageIndex Gets or sets the 0-based page index.
Gets or sets the number of records to display in one page of
PageIndex
GridView.
Gets a collection of GridViewRow objects that represents the
Rows
currently displayed rows in the GridView.
Gets an array that contains the names of the primary key field of
DataKeyNames
the currently displayed rows in the GridView.
Gets a collection of DataKey objects that represent the value of
DataKeys the primary key fields set in DataKeyNames property of the
GridView.

Events associated with GridView Control

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 :

<asp:GridView ID="GridView2" runat="server" BackColor="LightGoldenrodYellow"


BorderColor="Tan" Caption="2nd Grid" AllowPaging="False" AllowSorting="False"
BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None">
<FooterStyle BackColor="Tan" />
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
<PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
HorizontalAlign="Center" Font-Bold="True" />
<HeaderStyle BackColor="Tan" Font-Bold="True" />
<AlternatingRowStyle BackColor="PaleGoldenrod" />
</asp:GridView>

You might also like