AccessDataSource Constructor
Collapse the table of content
Expand the table of content

AccessDataSource Constructor ()


Initializes a new instance of the AccessDataSource class.

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

public AccessDataSource()

The following code example demonstrates how to use the AccessDataSource constructor to create a new AccessDataSource data source control and bind a CheckBoxList control to data in a Microsoft Access database.

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

<script runat="server">
private void Page_Load(Object sender, EventArgs e) {

  // Create the AccessDataSource.
  AccessDataSource accessDS = new AccessDataSource();
  accessDS.SelectCommand = "SELECT SupplierID, CompanyName " +
                           " FROM Suppliers WHERE Country ='Germany'";
  accessDS.DataFile = "~/App_Data/Northwind.mdb";

  // Add the AccessDataSource to the Page.Controls collection.

  // In programmatic scenarios, use the DataSource
  // property, not the DataSourceID property. The Select method
  // returns an IEnumerable list of data items.
  CheckBoxList1.DataSource = accessDS;

  // Explicitly call DataBind.

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



.NET Framework
Available since 2.0
Return to top
© 2016 Microsoft