Data Access
Data Access
ASP.NET includes features that enable you to add data access to your ASP.NET Web
pages with little or no code. You can connect to databases, XML data and files, and
business objects as data sources. You can then display data by using a variety of
controls that provide great flexibility in how you present data on the page.
ASP.NET includes data source controls that allow you to work with different types of
data sources such as a database, an XML file, or a middle-tier business object. Data
source controls connect to and retrieve data from a data source and make it
available for other controls to bind to, without requiring code. They can also support
modifying data.
ObjectDataSource
Enables you to work with a business object or other class and create Web
applications that rely on middle-tier objects to manage data. Supports advanced
sorting and paging scenarios unavailable with the other data source controls.
SqlDataSource
Enables you to work with Microsoft SQL Server, OLE DB, ODBC, or Oracle databases.
When used with SQL Server, supports advanced caching capabilities. The control
also supports sorting, filtering, and paging when data is returned as
a DataSet object.
XmlDataSource
Enables you to work with an XML file, especially for hierarchical ASP.NET server
controls such as the TreeView or Menu control. Supports filtering capabilities using
XPath expressions and enables you to apply an XSLT transformation to the data.
TheXmlDataSource allows you to update data by saving the entire XML document
with changes.
SiteMapDataSource
AccessDataSource
Enables you to work with a Microsoft Access database. Supports sorting, filtering,
and paging when data is returned as a DataSetobject.
SqlDataSource
The SqlDataSource control enables you to use a Web server control to access data
that is located in a relational data base. This can include Microsoft SQL Server and
Oracle databases, as well as OLE DB and ODBC data sources. You can use
the SqlDataSource control with data-bound controls such as theGridView, FormView,
and DetailsView controls to display and manipulate data on an ASP.NET Web page,
using little or no code.
Every ASP.Net web form control inherits the DataBind method from its parent
Control class, which gives it an inherent capability to bind data to at least one of its
properties. This is known as simple data binding or inline data binding.
GridView:
The GridView control displays data as a table and provides the capability to sort
columns, page through data, and edit or delete a single record.
DetailsView
The DetailsView control renders a single record at a time as a table and provides
the capability to page through multiple records, as well as to insert, update, and
delete records. The DetailsView control is often used in master-detail scenarios
where the selected record in a master control such as aGridView control determines
the record displayed by the DetailsView control.
FormView
The FormView control renders a single record at a time from a data source and
provides the capability to page through multiple records, as well as to insert,
update, and delete records, similar to the DetailsView control. However, the
difference between the FormView and the DetailsView controls is that
the DetailsView control uses a table-based layout where each field of the data
record is displayed as a row in the control. In contrast, the FormView control does
not specify a pre-defined layout for displaying a record. Instead, you create
templates that contain controls to display individual fields from the record. The
template contains the formatting, controls, and binding expressions used to lay out
the form.
Configuring SqlDataSource:
Steps
Parameterized Commands
You can use parameterized queries for commands and supply parameters at
run time
Using parameter commands
Objectdatasource and sqldatasource.
Customizing GridView
Functionality.
Gridview control support select , update and delete operation via properties
Like:
AutoGenerated Select
AutoGenerated Delete
AutoGenerated Edit
Multi-tier Application
Each time the ObjectDataSource needs to make a CRUD operation, it will try
to find (using reflection) the method to call (of course, you need to set some
properties to help it).
If it’s a static method, it will get the parameters and call it.
If it’s an instance method, it will create an object of the class, it will call the
method, and then destroy the instance (there is an exception to this, but
more about it later).
A GridView that will display the records from the "many" entity that are
associated with the selected "one" entity.
Menu
The Menu control allows you to develop both statically and dynamically
displayed menus for your ASP.NET web pages. You can configure the
contents of the Menu control directly in the control, or you can specify the
contents by binding the control to a data source.
You can define content for the Menu control in two ways: by interactively (or
programmatically) adding individual menu items or by data binding the
control to a Site Map or XML data source.
TreeView
The TreeView Web server control is used to display hierarchical data, such as
a table of contents or file directory, in a tree structure. It supports the
following features:
Automatic data binding, which allows the nodes of the control to be bound to
hierarchical data, such as an XML document.
Site navigation support through integration with
the SiteMapDataSource control.
Node text that can be displayed as either selectable text or hyperlinks.
SiteMapPath
Xmldatasource
SiteMapDataSource