Base Components

Using ADO in an Active Server Page

In this exercise, you will connect to the Northwind DSN using ADO in an ASP.

* To create a new project

  1. Start Microsoft Visual InterDev.
  2. From the File menu, click New .
  3. Select Web Project Wizard.
  4. In the Project Name , enter ADO.
  5. In the Location box, enter WA\Practice\Ch10\ado and click OK .
  6. Enter localhost for the server name and click Next .
  7. Click Finish .
* To create the starting page
  1. From the File menu, click New and select the Files tab.
  2. Select HTML Page .
  3. Enter a file name of default.htm .
  4. Delete the Insert HTML here comment.
  5. Right-click default.htm from the FileView window and click Open With .
  6. Select Microsoft FrontPage Editor and click Open .
  7. From the Insert menu, point to Form-Field and click One-line Text Box .
  8. Right-click the text box and click Form Field Properties .
  9. In the Name box, type txtID , and then click OK .
  10. Place the insertion point to the left of the text box and type Enter an Employee ID: .
  11. On a new line under the text box, add a push button to the form.
  12. Right-click the form and click Form Properties .
  13. Click Settings and in the action box, type employee.asp .
  14. Click OK to return to the FrontPage Editor.
  15. Save this page and exit the FrontPage Editor.
  16. Click Yes to reload the page in Visual InterDev.
  17. Review the default.htm page in Visual InterDev.
* To create the employee results page
  1. From the Visual InterDev File menu, click New .
  2. From the Files tab, select Active Server Page .
  3. In the name box, type employee.asp and click OK .
  4. Replace the <!-- Insert HTML Here --> comment with the following ASP script that creates an ADO recordset:
     <% empid = request.form("txtID") set rs = createobject("ADODB.Recordset") SQL = "Select * From Employees Where EmployeeID = " & empid rs.Open SQL, "DSN=nwind", adOpenKeyset %> 
  5. In the FileView window, right-click employee.asp and click Release Working Copy then click Yes to save changes.

    Before you can rename a file, you must release the local copy of the file to the server.

  6. Right-click employee.asp and click Rename . Change the file's extension to htm .

    The new file name should be employee.htm .

  7. Click OK .
  8. Right-click employee.htm and click Open With .
  9. Select Microsoft FrontPage Editor and click Open .
  10. Place the insertion point after the HTML Markup icon.
  11. Type Employee Information and center it on the page.
  12. From the Insert menu, add a horizontal line separator.
  13. Type Employee's First Name: and Employee's Last Name: on two new lines.
  14. Save the page and exit the FrontPage Editor.
  15. Open the employee.htm page in the Visual InterDev code window.
  16. Add a VBScript reference to the FirstName and LastName fields of the recordset in the HTML page. The script should look like this when you are finished:
     <p>Employee's First Name: <%= rs("firstname")%></p> <p>Employee's Last Name: <%= rs("lastname")%></p> 
  17. Save your work.
  18. Release a working copy of employee.htm and then rename it employee.asp .
* To test your work
  1. Right-click default.htm and click Preview in Browser .
  2. Enter an Employee ID of 1 and click Submit

    The employee, Nancy Davolio , should be returned.

  3. Close the Internet Explorer and Visual InterDev.

Lesson Summary

You can use ActiveX components to respond to a user request by using the Server object with an associated method. The first step in using an ActiveX server component is to create a reference to the component using the CreateObject method. Once you have created the reference you can call the methods of the component or set and retrieve properties of the component.

Microsoft IIS provides five base components to help to develop Web applications. In addition, you can create custom ActiveX server components using applications such as Microsoft Visual Basic. The base components include the Advertisement Rotator, Browser Capabilities, Database Access, Content Linking, and File Access. When you use the IIS Database Access server component, ADO accesses information stored in a database.



Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net