System.Web.UI.WebControls Namespace
.NET Framework version 2.0
Represents a Microsoft Access database to data-bound controls.
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, using 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 on 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, and 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 on data source caching, see Caching Data Using Data Source Controls.
The following table describes the features of the AccessDataSource control.
Capability |
Requirements |
Sorting |
Set the DataSourceMode property to DataSet. |
Filtering |
Set the FilterExpression property to a filtering expression used to filter the data when the Select method is called. |
Paging |
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 DataSet. |
Updating |
Set the UpdateCommand property to a SQL statement used to update data. This statement is typically parameterized. |
Deleting |
Set the DeleteCommand property to a SQL statement used to delete data. This statement is typically parameterized. |
Inserting |
Set the InsertCommand property to a SQL statement used to insert data. This statement is typically parameterized. |
Caching |
Set the DataSourceMode property to DataSet, 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.
For examples illustrating use of this control, see the individual member types of this class. For syntax information, see AccessDataSource in ASP.NET Syntax for Web Controls.
ASP.NET Data Source Controls