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

IMPORTANT NOTE: The AccessDataSource uses the Microsoft.Jet.OLEDB.4.0 driver which is a 32-bit driver taht is incompatible with 64-bit operating systems. So if you still intend to use rthe Jet.OLEDB.4.0 driver in a 64-bit server, you have to to build your application in 32-bit mode.

An alternative would be to use the SqlDataSource control, which, despite its name, can be used to connect to any relational database for which there is an ADO.NET provider, including Access databases.

The following code snippet shows how to use the SqlDataSource control to bind to data stored in an Access database.

<asp:sqldatasource id="..." runat="server"
   ConnectionString="<%$ ConnectionStrings: xxx %>"
   ProviderName="System.Data.OleDb"
   selectcommand="..." />

where xxxia the name of a connection string declared in your configuration file, pointing to the .mdb file in the default App_Data directory.

The following discussions apply only to 32-bit operating systems.

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

Since asp.net.ph is running on a 64-bit server, the AccessDataSource control will no longer work.

The following example demonstrates using the SqlDataSource control as mentioned above, to retrieve data from an Access database.

This is a typical display scenario wherein a DropDownList is used for selecting an option, with a GridView control showing the results of the selection.

Basically, this is how the controls work and interact:

  1. An SqlDataSource control is bound to the DropDownList control that provides a list of product categories from which the user makes a selection.
    <asp:sqldatasource id="ProductType" runat="server"
          ConnectionString="<%$ ConnectionStrings:gear %>"
          ProviderName="System.Data.OleDb"
          selectcommand="SELECT DISTINCT Type FROM Products"
          datasourcemode="DataReader" />
       
  2. Another SqlDataSource 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:sqldatasource id="Products" runat="server"
          ConnectionString="<%$ ConnectionStrings:gear %>"
          ProviderName="System.Data.OleDb"
          selectcommand="SELECT Type, ProductId, Brand, Model, Description, Price FROM Products"
          filterexpression="Type='{0}'">
    
          <filterparameterss>
             <asp:controlparameter controlid="filterType" 
                propertyname="SelectedValue" />
          </filterparameters>
    
       </asp:sqldatasource>>
  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"
       ... />

Using SqlDataSource to Connect to OleDb Data
Run Sample | View Source
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