asp.net.ph

Skip Navigation Links

AccessDataSource Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Represents a data source control that works with Microsoft Access databases.

Declarative Syntax

For information on the individual members of this class, see AccessDataSource in the class library.

Remarks

The AccessDataSource class is a data source control used for working with Microsoft Access databases in ASP.NET Web Forms.

At a minimum, an AccessDataSource control needs at least the following properties to be set in order to function:

  1. the DataFile property, which sets the location of the Microsoft Access .mdb file to work with, and
  2. the SelectCommand property, which specifies the SQL query to execute on the data file.

For security, Access databases should be located in the App_Data directory of the Web application, as this location is internally configured to reject direct HTTP requests to the data files from client browsers.

The data files can be accessed only by applications running on the same domain, using an absolute or a relative path, such as

datafile = "~/App_Data/Northwind.mdb"

The AccessDataSource class does not support connecting to Access databases that are protected by a user name or password, because the ConnectionString property of the control is set internally and can not be modified.

In these cases, the SqlDataSource control should be used, as this control provides for specifying parameters in the connection string.

Data controls are bound to an AccessDataSource using the DataSourceID property of the data-bound control. For more information on binding a data-bound control to data source controls, see Binding to Data Using a Data Source Control.

For more information on using the AccessDataSource control, see AccessDataSource Web Server Control.

Syntax Example

The following example demonstrates a typical display scenario using AcessDataSource controls with a DropDownList and a GridView control.

Basically, this is how the controls work and interact:

  1. An AccessDataSource control is bound to the DropDownList control that provides a list of product categories from which the user makes a selection.
    <asp:accessdatasource id="ProductType" runat="server"
       datafile = "~/app_data/gear.mdb"
       selectcommand = "SELECT distinct Type FROM Products"
       datasourcemode = "DataReader" />
    
    ...
    
    Select Category: <asp:dropdownlist id="filterType" runat="server"
       datasourceid="ProductType" datatextfield = "Type"
       autopostback />
  2. Another AccessDataSource control is bound to the GridView control, whose SelectCommand property is set to an appropriate SQL query that is filtered by the given FilterExpression, which is based on the user selection.
    <asp:accessdatasource id="Products" runat="server"
       datafile = "~/app_data/gear.mdb"
       selectcommand = "SELECT Type, ProductId, Brand, Model, Description, Price FROM Products"
       filterexpression = "Type='{0}'">
       <filterparameters>
          <asp:controlparameter controlid="filterType" 
             propertyname = "SelectedValue" />
       </filterparameters>
    
    </asp:accessdatasource>
  3. Each time the user makes a selection, the filtered data from the specified datafile is displayed in the GridView control.
    <asp:gridview id="ProductsGrid" runat="server"
       datasourceid="Products"
       ... />

 Show me 

See Also

AccessDataSource Class   AccessDataSource Web Server Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note