asp.net.ph

Skip Navigation Links

Retrieving Data Using the AccessDataSource Control

Controls You Can Use on Web Forms   ASP.NET Data Source Controls   AccessDataSource Control


Basically, retrieving data from a Microsoft Access database using the AccessDataSource control can be done in two ways:

  1. by specifying the SQL query to execute directly against the data file, or
  2. by referencing a query stored in the data file itself.

In the first case, you specify the SQL query by setting the AccessDataSource control’s SelectCommand property as shown in the following example.

<asp:accessdatasource id="ProductType" runat="server"
   datafile="~/app_data/gear.mdb"
   selectcommand="SELECT DISTINCT Type FROM Products"
   datasourcemode="DataReader" />

 Show me 

In the second case, you specify the name of the Microsoft Access query to execute as the value of the SelectCommand, and set the SelectCommandType property value to StoredProcedure, as shown in the following example.

<asp:accessdatasource id="zipcodes" runat="server"
   datafile="~/app_data/usa.mdb"
   selectcommand="[Zipcodes By State and County]"
   selectcommandtype="StoredProcedure">

   <selectparameters>
      <asp:controlparameter controlid="lstStates" 
         propertyname="SelectedValue" />
      <asp:controlparameter controlid="lstCounties" 
         propertyname="SelectedValue" />
   </selectparameters>

</asp:accessdatasource>

 Show me 



© 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