System.Web.UI.WebControls.AccessDataSource Class

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

See Also: AccessDataSource Members

Syntax

[System.Drawing.ToolboxBitmap("")]
[System.ComponentModel.Designer("System.Web.UI.Design.WebControls.AccessDataSourceDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
public class AccessDataSource : SqlDataSource

Remarks

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

One of the unique characteristics of the System.Web.UI.WebControls.AccessDataSource control is that you do not set the AccessDataSource.ConnectionString property. All you need to do is set the location of the Access (.mdb) file in the AccessDataSource.DataFile property and the System.Web.UI.WebControls.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 System.Web.UI.WebControls.AccessDataSource class does not support connecting to Access databases that are protected by a user name or password, because you cannot set the AccessDataSource.ConnectionString property. If your Access database is protected by a user name or password, use the System.Web.UI.WebControls.SqlDataSource control to connect to it so that you can specify a complete connection string.

You bind data-bound controls to an System.Web.UI.WebControls.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 System.Web.UI.WebControls.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 AccessDataSource.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 SqlDataSource.SelectCommand, SqlDataSourceView.UpdateCommand, SqlDataSourceView.InsertCommand, and SqlDataSourceView.DeleteCommand properties must match the order of any System.Web.UI.WebControls.Parameter objects that are in the corresponding parameter collection. If no parameter collection is specified on the System.Web.UI.WebControls.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 the SqlDataSource and AccessDataSource Controls with Parameters.

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

The following table describes the features of the System.Web.UI.WebControls.AccessDataSource control.

Sorting

Set the SqlDataSource.DataSourceMode property to the SqlDataSourceMode.DataSet value.

Filtering

Set the SqlDataSource.FilterExpression property to a filtering expression used to filter the data when the SqlDataSource.Select(System.Web.UI.DataSourceSelectArguments) method is called.

Paging

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

Updating

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

Deleting

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

Inserting

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

Caching

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

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

There is no visual rendering of the System.Web.UI.WebControls.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 System.Web.UI.DataSourceControl.EnableTheming and System.Web.UI.DataSourceControl.SkinID properties.

Declarative Syntax

Example

<asp:AccessDataSource
    CacheDuration="string|

Requirements

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0