ASP.NET Data Access Overview
Web applications commonly access data sources for storage and retrieval of dynamic data. You can write code to access data using classes from the System.Data namespace (commonly referred to as ADO.NET) and from the System.Xml namespace. This approach was common in previous versions of ASP.NET.
However, ASP.NET also enables you to perform data binding declaratively. This requires no code at all for the most common data scenarios, including:
Selecting and displaying data.
Sorting, paging, and caching data.
Updating, inserting, and deleting data.
Filtering data using run-time parameters.
Creating master-detail scenarios using parameters.
ASP.NET includes several types of server controls that participate in the declarative data binding model, including data source controls, data-bound controls, and the query extender control. These controls manage the underlying tasks that are required by the stateless Web model in order to display and update data in ASP.NET Web pages. The controls let you add data-binding behavior to a page without having to understand details of the page request life cycle.
Data source controls are ASP.NET controls that manage the tasks of connecting to a data source and reading and writing data. Data source controls do not render any user interface, but instead act as an intermediary between a particular data store (such as a database, business object, or XML file) and other controls on the ASP.NET Web page. Data source controls enable rich capabilities for retrieving and modifying data, including querying, sorting, paging, filtering, updating, deleting, and inserting. Data source controls derive from ContextDataSource, which is the base class that provides the context type that data source controls use. This base class enables you to create data source controls that support data models such as Entity Framework and WCF Data Services.
ASP.NET includes the following data source controls:
|
Data source control |
Description |
|---|---|
|
Enables you to work with a Microsoft Access database. For more information, see AccessDataSource Web Server Control Overview. |
|
|
Enables you to use Language-Integrated Query (LINQ) in an ASP.NET Web page through declarative markup in order to retrieve and modify data from a data object. Supports automatic generation of select, update, insert, and delete commands. The control also supports sorting, filtering, and paging. |
|
|
Enables you to work with a business object or other class and create Web applications that rely on middle-tier objects to manage data. For more information, see ObjectDataSource Web Server Control Overview. |
|
|
Used with ASP.NET site navigation. For more information, see ASP.NET Site Navigation. |
|
|
Enables you to work with ADO.NET managed data providers, which provide access to Microsoft SQL Server, OLE DB, ODBC, or Oracle databases. For more information, see SqlDataSource Web Server Control Overview. |
|
|
Enables you to bind to data that is based on the Entity Data Model (EDM). Supports automatic generation of update, insert, delete, and select commands. The control also supports sorting, filtering and paging. For more information, see EntityDataSource Web Server Control Overview. |
|
|
Enables you to work with an XML file, which is especially useful for hierarchical ASP.NET server controls such as the TreeView or Menu control. For more information, see XmlDataSource Web Server Control Overview. |
Data-source controls can also be extended to support additional data access storage providers.
For more information on data source controls, see Data Source Controls Overview.
Filtering data in a data-driven Web site typically requires that you create a Where clause in the query that is associated with the data source control. This method of filtering data can be difficult, and in some cases it does not expose the full functionality of the underlying data source. In order to make it easier to filter data in a page, ASP.NET provides the QueryExtender control.
You can use the QueryExtender control to do the following:
-
Provide string-search capabilities in a Web page.
-
Define a range of values to search.
-
Compare a specified value to a property value in a table.
-
Provide sorting capabilities for the filtered data.
-
Define custom filtering.
Using the QueryExtender control for filtering data is more efficient than using a Where clause because you do not have to learn the query language for the data provider that is used by the query extender control.
The EntityDataSource and LinqDataSource controls support the QueryExtender control.
For more information, see QueryExtender Web Server Control Overview.
Data-bound controls render data as markup to the requesting browser. A data-bound control can bind to a data source control and automatically fetch data at the appropriate time in the page request lifecycle. Data-bound controls can take advantage of the capabilities provided by a data source control including sorting, paging, caching, filtering, updating, deleting, and inserting. A data-bound control connects to a data source control through its DataSourceID property.
ASP.NET includes the data-bound controls described in the following table.
Note
|
|---|
|
The DataGrid control available in ASP.NET version 1.0 and version 1.1 has been superseded by the GridView control, which includes expanded capabilities for sorting, paging, and modifying data. Existing pages that use the DataGrid control will continue to function. As with other data controls, the DataGrid control has been enhanced to interact with data source controls. |
Note
|
|---|
|
The ListView control supersedes the Repeater control and the DataList control. Existing pages that use those controls will continue to function. The ListView control simplifies the implementation of many common scenarios. |
For more information, see ASP.NET Data-Bound Web Server Controls Overview.
Language-Integrated Query (LINQ) provides a unified programming model for querying and updating data from different types of data sources, and extends data capabilities directly into the C# and Visual Basic languages. LINQ applies the principles of object-oriented programming to relational data. To work with LINQ, you can use the LinqDataSource control. You can also create LINQ queries directly in order to access data from a Web page. For more information, see Using LINQ with ASP.NET.
ASP.NET Dynamic Data is a framework that enables you to create data-driven ASP.NET Web applications quickly. Dynamic Data automatically discovers the data model at run time and determines UI behavior from the data model. A scaffolding framework instantly provides a functional Web site for displaying and editing data. This scaffolding can then be customized using metadata, templates, or by creating standard ASP.NET pages to override the default behavior. Existing ASP.NET Web applications can easily integrate pieces of the scaffolding logic into their web pages. For more information about Dynamic Data, see ASP.NET Dynamic Data Content Map
You can add Dynamic Data features to an ASP.NET Web Application without using scaffolding. When Dynamic Data is enabled in an ASP.NET Web application, the Web application can take advantage of the following features:
-
Run-time data field validation.
-
The ability to use in-memory page templates.
-
The ability to apply custom metadata to various data fields by using attributes from the System.ComponentModel.DataAnnotations namespace.
For more information, see Walkthrough: Enabling Dynamic Data in ASP.NET Data-Bound Controls.
Note