Page view counter

These tutorials demonstrate selected features in ASP.NET version 2.0, but they are compatible with later versions of ASP.NET as well. For the current documentation, see the ASP.NET portal on the MSDN Web site.



   Welcome   |   ASP.NET   |   Web Services   |   Class Browser   
  |   I want my samples in...      

ASP.NET Quickstart Tutorials

Performing Data Access

What's New in 2.0

  • Data Source Controls - ASP.NET 2.0 introduces declarative data source controls that expose data from a backend store, such as a SQL database, middle-tier business object, or XML file, to data-bound UI controls on a page. Data source controls also expose capabilities such as sorting, paging, caching, updating, inserting and deleting data that UI controls can automatically take advantage of without requiring code.

  • New Data-bound Controls - In addition to the data-bound controls in ASP.NET v1.x, ASP.NET includes new data-bound UI controls such as GridView, DetailsView, FormView, TreeView, and Menu, which can be customized to display data in a variety of formats. The GridView, DetailsView, and FormView controls can also automatically take advantage of data source capabilities, making is easy to add sorting, paging, and update operations to data-driven pages.

  • Data Control Parameters - Data sources can accept input parameters from a variety of sources using the new data control parameter objects in ASP.NET 2.0. These parameter objects allow you to easily supply server control property values, session, application, cookie and querystring fields, and user profile properties to parameterized data operations. Using these parameters enables filtering and master-details scenarios with little or no custom code.

  • Improved Data Binding Syntax - The DataBinder.Eval data binding syntax in ASP.NET has been simplified for the common scenario of binding a control in a data-bound template. It is also possible to associate a two-way data binding with control properties in a template, to allow values to be automatically passed to a data source update, insert, or delete operation. For hierarchical XML data, ASP.NET 2.0 also includes an XPath-based data binding syntax.

  • Local File Databases Using SQL Express - For ease of development, ASP.NET 2.0 now supports the ability to connect to a SQL Express database as a local file in the application, eliminating the need to provision the database to a server just to perform development work. Of course, you can still connect to server-based SQL databases as well.
This section describes these and other data access features in ASP.NET 2.0.

Nearly every dynamic web application performs some kind of data access, and fortunately ASP.NET 2.0 makes this incredibly easy to do. Unlike ASP.NET 1.0, which required developers to write custom code in order retrieve and bind data to server controls, ASP.NET 2.0 enables a declarative solution for data binding which requires no code at all for the most common data scenarios, such as:
  • Selecting and displaying data
  • Sorting, Paging and Caching Data
  • Updating, Inserting and Deleting Data
  • Filtering or Master-Details Using Parameters
ASP.NET 2.0 introduces two types of server controls that participate in this declarative data binding model. These two types of data controls handle the complexity of the stateless Web model for data scenarios, so developers don't need to understand page request lifecycle events just to perform data binding. Another benefit of this control-based model is that it can be easily extended to support additional data access storage providers.

Data Source Controls

Data source controls have no rendering, but instead represent a particular backend data store, for example a database, business object, XML file, or XML Web Service. Data source controls also enable rich capabilities over data - such as sorting, paging, filtering, updating, deleting, and inserting - that data-bound UI controls can automatically use. ASP.NET includes the following server controls out-of-the-box:

SqlDataSourceEnables binding to a SQL database represented by an ADO.NET provider, such as Microsoft™ SQL Server, OLEDB, ODBC, or Oracle.
ObjectDataSourceEnables binding to a middle-tier object such as a data access layer or business component.
AccessDataSourceEnables binding to a Microsoft™ Access (Jet) database.
SiteMapDataSourceEnables binding to the hierarchy exposed by an ASP.NET 2.0 site navigation provider.
XmlDataSourceEnables binding to an XML file or document.

Data-bound Controls

Data-bound controls are UI controls that render data as markup to the requesting client device or browser. A data-bound control can auto-bind to data exposed from a data source and will fetch data at the appropriate time in the page request lifecycle. These controls can optionally take advantage of data source capabilities such as sorting, paging, filtering, updating, deleting, and inserting. A data-bound control connects to a data source control through its DataSourceID property. You may be familiar with some of the data-bound controls in ASP.NET v1.x, such as DataGrid, DataList, Repeater, and list controls like DropDownList. ASP.NET 2.0 contains several new data-bound controls as well, such as:

GridViewRenders data in a grid format. This control is an evolution of the DataGrid control, and can automatically take advantage of data source capabilities.
DetailsViewRenders a single data item in a table of label/value pairs, similar to the form view in Microsoft™ Access. This control can also automatically take advantage of data source capabilities.
FormViewRenders a single data item at a time in a form defined by a custom template. Renders a single data item in a table of label/value pairs, similar to the form view in Microsoft™ Access. This control can also automatically take advantage of data source capabilities.
TreeViewRenders data in a hierarchical tree view of expandable nodes.
MenuRenders data in a hierarchical dynamic menu (including flyouts).

This section demonstrates these and other new data features in ASP.NET 2.0.