This documentation is archived and is not being maintained.

AccessDataSource Class

Represents a Microsoft Access database for use with data-bound controls.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

<ToolboxBitmapAttribute(GetType(AccessDataSource))> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class AccessDataSource _
	Inherits SqlDataSource
Dim instance As AccessDataSource
<asp:AccessDataSource />

The AccessDataSource class is a data source control that works with Microsoft Access databases. Like its base class, SqlDataSource, the AccessDataSource control uses SQL queries to perform data retrieval.

One of the unique characteristics of the AccessDataSource control is that you do not set the ConnectionString property. All you need to do is set the location of the Access (.mdb) file in the DataFile property and the AccessDataSource takes care of the underlying connection to the database. You should place Access databases in the App_Data directory of the Web site and reference them by a relative path (for example, ~/App_Data/Northwind.mdb). This location offers additional security for data files, because they are not served if they are requested directly by the client Web browser.

The AccessDataSource class does not support connecting to Access databases that are protected by a user name or password, because you cannot set the ConnectionString property. If your Access database is protected by a user name or password, use the SqlDataSource control to connect to it so that you can specify a complete connection string.

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

Because the AccessDataSource control is specific to only one database product, it always uses the same provider—the System.Data.OleDb .NET data provider. For this reason, the ProviderName property is read-only. When using the System.Data.OleDb provider, the order of the parameters in a parameterized SQL statement is significant; any parameterized SQL queries that you specify in the SelectCommand, UpdateCommand, InsertCommand, and DeleteCommand properties must match the order of any Parameter objects that are in the corresponding parameter collection. If no parameter collection is specified on the AccessDataSource, the order of parameters that are supplied to these operations must match the order in which they appear in the underlying SQL statement. For more information, see Using Parameters with the SqlDataSource Control.

The AccessDataSource control supports the same caching behavior that its base class supports. Use caching to increase the performance of pages that use the AccessDataSource control. For more information about data source caching, see Caching Data Using Data Source Controls.

The following table describes the features of the AccessDataSource control.




Set the DataSourceMode property to the DataSet value.


Set the FilterExpression property to a filtering expression used to filter the data when the Select method is called.


The AccessDataSource does not support direct paging operations on an Access database. A data-bound control, such as the GridView, can page over the items returned by the AccessDataSource, if the DataSourceMode property is set to the DataSet value. 


Set the UpdateCommand property to a SQL statement used to update data. This statement is typically parameterized.


Set the DeleteCommand property to a SQL statement used to delete data. This statement is typically parameterized.


Set the InsertCommand property to a SQL statement used to insert data. This statement is typically parameterized.


Set the DataSourceMode property to the DataSet value, the EnableCaching property to true, and the CacheDuration and CacheExpirationPolicy properties according to the caching behavior you want for your cached data.

As with all data source controls, the AccessDataSource control is associated with a strongly typed data source view class. Just as the AccessDataSource control extends the SqlDataSource control, the AccessDataSourceView class extends the SqlDataSourceView class. The AccessDataSourceView class overrides a few of the SqlDataSourceView methods to use the System.Data.OleDb .NET data provider.

There is no visual rendering of the AccessDataSource control; it is implemented as a control to enable declarative persistence and to permit, optionally, participation in state management. As a result, you cannot set properties that support visual features, such as the EnableTheming and SkinID properties.

How to: Display Ads From a Database Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications
How to: Bind to Data in a Templated ControlBuilding ASP .NET Web Applications
How to: Display Ads From a Database Using the AdRotator Web Server ControlBuilding ASP .NET Web Applications
How to: Bind to Data in a Templated ControlBuilding ASP .NET Web Applications
How to: Connect to an Access Database Using the AccessDataSource Control (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Add Repeater Web Server Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
Walkthrough: Creating a Web Page to Display Access Database DataBuilding ASP .NET Web Applications in Visual Studio
How to: Bind to Data in a Templated Control in Visual StudioBuilding ASP .NET Web Applications in Visual Studio

The following code example demonstrates a common display and update scenario with the GridView control. The SelectCommand property is set to an appropriate SQL query, and data from the Northwind database is displayed in the GridView control. Because a UpdateCommand property is also specified and the AutoGenerateEditButton property is set to true, you can edit and update the records with no additional code. The GridView control handles adding parameters to the UpdateParameters collection; the GridView control passes the parameter values for the BoundField objects first, followed by the values of fields that are specified by the DataKeyNames property. The GridView calls the Update method automatically. If you want to order the parameters, explicitly, specify an UpdateParameters collection on the AccessDataSource.

<%@Page  Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
  <head runat="server">
    <title>ASP.NET Example</title>
    <form id="form1" runat="server">

        selectcommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
        updatecommand="Update Employees SET FirstName=?,LastName=?,Title=? WHERE EmployeeID=@EmployeeID">

          <asp:boundfield headertext="First Name" datafield="FirstName" />
          <asp:boundfield headertext="Last Name" datafield="LastName" />
          <asp:boundfield headertext="Title" datafield="Title" />


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0