Microsoft KB Archive/180814

= How to display records from an Access database with ASP =

Article ID: 180814

Article Last Modified on 5/2/2006

-

APPLIES TO


 * Microsoft Visual InterDev 1.0 Standard Edition
 * Microsoft Internet Information Server 3.0
 * Microsoft Internet Information Server 4.0

-



This article was previously published under Q180814





For a Microsoft Visual Basic .NET version of this article, see 308278.



SUMMARY
This article shows you how to create a Web interface that displays information from an Access 97 relational database using Visual InterDev.

There are four main steps in this process:


 * 1) Create the Web project.
 * 2) Add a Data Connection to Your project.
 * 3) Create an Active Server Pages (ASP) page and Add it to a Data Command Control.
 * 4) Write Code to Act on the Recordset Object Returned by the Data Command Control.



MORE INFORMATION
Follow the steps below to create an interface that reads data stored in an Access 97 database.

Step 1: Create the Web Project

 * 1) Launch Visual InterDev.
 * 2) On the File menu, click New.
 * 3) Select the Web Project Wizard from the list on the Projects tab.
 * 4) Enter MyDatabaseApp for the name of your Web project in the Project Name box (this is the name of your project stored on your remote workstation).
 * 5) In the Location box, enter a path or click the ellipsis (...) to browse your local workstation for a place to store your project and files.
 * 6) Click OK to continue to the next step.
 * 7) Type or select the server for your Web, and click Next.
 * 8) In Step 2 of the wizard, select "Create a new Web."
 * 9) Type DB for the name of your new Web. This helps to demonstrate the difference between a project and a Web.
 * 10) Clear "Enable full text searching for pages in this Web."
 * 11) Click Finish to create your new Web.

Step 2: Add a Data Connection to Your Project
 From the Project menu, point to Add to Project, and then click Data Connection. Click New on the File Data Source tab. Select "Microsoft Access Driver (*.mdb)" and click Next. Click Browse. By default, this places you in the Data Source folder located in the WinNT\ODBC directory on Windows NT or the Program Files\ Common Files\ODBC directory on Windows 95. In the File Name box, type MyDataSource and click Save. The full path to your new Data Source Name (DSN) file appears in the box.</li> Click Next, then click Finish.</li> In the "ODBC Microsoft Access 97 Setup" dialog box, click Select (located in the Database section of the dialog box).</li>  Browse or type in the path to the Adventure Works (AdvWorkds.mdb) database.

NOTES:

The Adventure Works example site is installed by default when you add Active Server Pages to Microsoft Internet Information Server. The site is installed by default into the InetPub\ASPSamp\AdvWorks directory.

If your database resides on a machine other than the Microsoft Internet Information Server server, you may want to use a Universal Naming Convention (UNC) path so that the server can locate it on your network. Following is a sample UNC path: <pre class="fixed_text">     \\SERVERNAME\ROOTSHARENAME\InetPub\ASPSamp\AdvWorks\AdvWorks.mdb SERVERNAME represents the name of your server and ROOTSHARENAME represents the share name of your root directory.

Note also that when you use an Access 97 database, you must set the NTLM CHANGE permissions for the directory where the database is located. This means that the IUSR_ account, for anonymous user logon, must have CHANGE permissions for the entire directory.

For additional information, please see the following article in the Microsoft Knowledge Base:

175804 PRB: Server Object Error 'ASP 0177:80040154' Server.CreateObject

</li> Click OK to select the database for your DSN.</li> Click OK to complete the DSN setup.</li> Select MyDataSource.dsn from the list in the Select Data Source dialog box.</li> Click OK to complete the process.</li></ol>

Step 3: Create an ASP Page and Add It to a Data Command Control
<ol> On the Project menu, point to Add to Project, and click New.</li> Select Active Server Page on the Files tab.</li> Type "Database" in the File Name box, and leave all other default options.</li> Click OK to create the page.</li> Leave the "" line selected in the code window. On the Insert menu, point to Into HTML, and click ActiveX Control.</li> Click the Design-time tab in the Insert ActiveX Control dialog box.</li> Select the Data Command control from the list provided, and click OK. A Properties dialog box for your new control appears.</li> Leave "DataCommand1" in the ID box, and select DataConn from the DataConnection list. This is the DataConnection that you created in step 2.</li> <li>Click SQL Builder to build a SQL statement that returns a Recordset.</li> <li>Click the plus sign (+) to expand the Tables tree in the Data View window.</li> <li>Drag the Products table into the Query Builder window.</li> <li> Select * (All Columns) in the Products table (located in the Query Builder window) to create the following SQL statement: <pre class="fixed_text">     SELECT Products.* FROM Products </li> <li>On the File menu, click Close to close the Query Builder, and click Yes when prompted to update DataCommand1.

You should see the new SQL statement in the Command Text box of the Properties dialog box.</li> <li>Close the DataCommand1 control window.

Note that Visual InterDev creates the code necessary to execute the query against the Access database and to return the results in the Recordset object.</li></ol>

Step 4: Write Code to Act on the Recordset Object Returned by the Data

Command Control
<ol> <li> Place the following code after the tag in your ASP page: <%       Dim fldTemp For Each fldTemp In DataCommand1.Fields Response.Write fldTemp.Value & "<BR>" Next %>                   </li> <li>On the File menu, click Save to save the ASP page.</li> <li>Right-click the ASP page file name in the FileView window, and select "Preview in browser."</li></ol>

<div class="references_section">