Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 56 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
56
Dung lượng
0,95 MB
Nội dung
Module 7: Universal Data Access with ADO 2.5 Contents Overview Using ADO 2.5 Retrieving Data from a Database 10 Lab 7.1: Using ADO Commands Efficiently 16 Accessing Web Data 31 Lab 7.2: Accessing Data From a Web Site 44 Best Practices 47 Review 49 Information in this document is subject to change without notice The names of companies, products, people, characters, and/or data mentioned herein are fictitious and are in no way intended to represent any real individual, company, product, or event, unless otherwise noted Complying with all applicable copyright laws is the responsibility of the user No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, for any purpose, without the express written permission of Microsoft Corporation If, however, your only means of access is electronic, permission to print one copy is hereby granted Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property 2000 Microsoft Corporation All rights reserved Microsoft, BackOffice, MS-DOS, Windows, Windows NT, Active Directory, ActiveX, FrontPage, PowerPoint, Visual Basic, and Visual C++ are either registered trademarks or trademarks of Microsoft Corporation in the U.S.A and/or other countries The names of companies, products, people, characters, and/or data mentioned herein are fictitious and are in no way intended to represent any real individual, company, product, or event, unless otherwise noted Other product and company names mentioned herein may be the trademarks of their respective owners Module 7: Universal Data Access with ADO 2.5 iii Instructor Notes Presentation: 105 Minutes Lab: 60 Minutes This module describes how to use Microsoft ActiveX® Data Objects (ADO) 2.5 for universal data access This material was prepared for students who already know how to access relational data by using previous versions of ADO The module focuses on learning how to access databases efficiently in an enterprise solution and how to access Web data by using the new ADO Record and Stream objects introduced in Microsoft Windows 2000 After completing this module, students will be able to: ! Describe the major components of the ADO 2.5 object model ! Describe how to use ADO to access databases efficiently ! Use the Microsoft OLE DB Provider for Internet Publishing with ADO 2.5 to retrieve hierarchical data from a Web site ! Use the Recordset, Record, and Stream objects to access Web-based data In the first lab, students will learn how to use an ADO command object to make efficient calls to a stored procedure In the second lab, students will use the Microsoft OLE DB Internet Publishing Provider and ADO 2.5 to retrieve hierarchical data from a Web site They will use a Recordset object to list the documents in the Web site, a Record object to retrieve a specific document, and a Stream object to preview the contents of a document Materials and Preparation This section provides you with the required materials and preparation tasks that are needed to teach this module Required Materials To teach this module, you need the following materials: ! Microsoft PowerPoint® file 1907A_07.ppt ! Module 7: Universal Data Access with ADO 2.5 ! Lab 7.1: Using ADO Commands Efficiently ! Lab 7.2: Accessing Data From a Web Site Preparation Tasks To prepare for this module, you should: ! Read all of the materials for this module ! Complete the lab ! Read the instructor notes and margin notes for the module ! Practice the demonstrations and lab exercises Demonstration This section provides demonstration procedures that will not fit in the margin notes or are not appropriate for the student notes iv Module 7: Universal Data Access with ADO 2.5 Using ADO to Access Web Data ! Prepare for the demonstration Use Windows Explorer to view the contents of the \Democode\Mod07 folder Right-click the Sales folder and choose Properties On the Web Sharing tab, click the Share this folder option button Leave the default alias (Sales) and ensure that all Access Permissions check boxes are checked Then click OK Click Yes to accept the warning message and then click OK on the Properties dialog box ! Demonstrate opening records and recordsets Open the Sales.vbp project in the \Democode\Mod07 folder Display the variable declarations in the General Declarations section Explain that the objPendingFolder record object will represent the PendingOrders folder in the Sales intranet, the objPending recordset object will represent the contents of the PendingOrders folder, and that the objOrder record object will represent the currently selected record in the objPending recordset Display the code in the Form_Load event procedure Explain that the objPendingFolder record object is opened by using a relative URL for the PendingOrders folder The Absolute URL to the Sales Web site is specified in the ConnectionString argument Display the ListOrders subprocedure Explain that this procedure opens the objPending recordset object by using the GetChildren method of the objPendingOrders record object, and that it loops through the records and adds the first field (the relative URL of the record) to a list box Display the lstPendingOrders_Click() event procedure Explain that this code is used to synchronize the current record in the objPending recordset with the currently selected item in the list box Run the project and note that it displays the three files in the PendingOrders folder Stop the project ! Demonstrate file manipulation using the record object Use Windows Explorer to show students the Sales Web folder hierarchy Display the code window for frmSales in the Sales.vbp project and show the students the cmdLog_Click event procedure Explain that this code copies the currently selected file to the OrderLog folder Display the cmdApprove_Click event procedure Explain that this code moves the currently selected file to the ApprovedOrders folder Module 7: Universal Data Access with ADO 2.5 Display the cmdDelete_Click event procedure Explain that this code deletes the selected file Run the application and select Order1.xml Click Log Switch to Windows Explorer to show that the file has been copied to the OrderLog folder Switch back to the running project and select Order2.xml Click Approve 10 Switch to Windows Explorer to show that the file has been moved to the ApprovedOrders folder 11 Switch back to the running project and select Order3.xml 12 Click Delete 13 Switch to Windows Explorer to show that the file has been deleted 14 Stop the project ! Demonstrate file access using the Stream object Display the code in the cmdPreview_Click event procedure Explain that this code opens the currently selected record from the objPending recordset and then uses a stream object to open the contents of the file for reading The file is an ASCII text file and its contents are displayed in a message box Run the project Select Order1.xml Click Preview to view the contents of the file Stop the project Module Strategy Use the following strategy to present this module: ! Using ADO 2.5 Discuss Microsoft’s data access strategy Explain that ADO 2.5 is provided with Microsoft Windows 2000 Server as part of the Microsoft Data Access Components (MDAC) Discuss new ADO 2.5 features and review how to use ADO to connect to a data source, retrieve selected data, and manipulate data ! Retrieving Data from a Database Explain that in an enterprise solution, it is critical that developers access databases efficiently so that the maximum number of users can simultaneously access the database with acceptable response times Discuss the importance of following recommended design guidelines and using efficient data access programming techniques v vi Module 7: Universal Data Access with ADO 2.5 Highlight some of the ways in which you can use ADO to access databases efficiently, such as using the append technique to populate parameter collections Note the use of slide builds to explain ADO disconnected recordsets Use the builds to explain the process of opening, disconnecting, reconnecting, and batch updating a recordset, as well as handling conflicts ! Accessing Web Data Explain that many organizations are storing an increasing amount of data in Web folders instead of in relational databases Consequently, it is becoming important to be able to access data from a Web site Discuss that there is an OLE DB provider for Internet Publishing that can be used with ADO 2.5 to retrieve hierarchical data from a Web site Use the demonstration application to highlight each of the concepts covered You may choose to highlight these concepts incrementally as you discuss each topic or to run the demonstration after all of the topics have been taught ! Best Practices Finish this module with a discussion of some of the best practices to follow when using ADO 2.5 for Universal Data Access Mention that the practical implementation for most of these best practices was covered in various sections throughout the module Module 7: Universal Data Access with ADO 2.5 # Overview Slide Objective To provide an overview of the module topics and objectives Lead-in In this module, you will learn how to use ADO 2.5 for Universal Data Access You will learn how to use the OLE DB Provider for Internet Publishing to retrieve hierarchical data from a Web site ! Using ADO 2.5 ! Retrieving Data from a Database ! Lab 7.1: Using ADO Commands Efficiently ! Accessing Web Data ! Lab 7.2: Accessing Data from a Web Site ! Best Practices ! Review In this module, you will learn how learn how to use Microsoft® ActiveX® Data Objects (ADO) 2.5 for Universal Data Access This module was prepared for students who already know how to access relational data by using previous versions of ADO As a result, you will focus on learning how to access databases efficiently in an enterprise solution and how to access Web data by using the new Record and Stream objects Objectives After completing this module, you will be able to: ! Describe the major components of the ADO 2.5 object model ! Describe how to use ADO to access databases efficiently ! Use Microsoft OLE DB Provider for Internet Publishing with ADO 2.5 to retrieve hierarchical data from a Web site ! Use the Recordset, Record, and Stream objects to access Web-based data Module 7: Universal Data Access with ADO 2.5 # Using ADO 2.5 ! Understanding OLE DB ! The ADO 2.5 Object Model ! Using ADO Objects ADO 2.5 is provided with Microsoft Windows® 2000 Server as part of the Microsoft Data Access Components (MDAC) In this section, you will learn about Microsoft’s data access strategy You will also learn how to use ADO 2.5 to connect to a data source, retrieve selected data, and manipulate data This section includes the following topics: ! Understanding OLE DB ! The ADO 2.5 Object Model ! Using ADO Objects Module 7: Universal Data Access with ADO 2.5 Understanding OLE DB Microsoft’s data access strategy is based on the OLE DB application programming interface (API) OLE DB provides access to a diverse range of data sources by using OLE DB providers An OLE DB provider is a specialized software driver, written for a specific data source, which enables the OLE DB API to abstract the data source and present a standard programming interface to client applications You can write code to directly manipulate the programming interface exposed by OLE DB However, this code can be complex and requires extensive lowlevel knowledge of the OLE DB API Alternatively, you can use the Automation objects in the ADO 2.5 object library to access the OLE DB interface and manipulate data Using these objects provides a less complex programming model and enables you to access data from compiled languages such as Microsoft Visual Basic® and Microsoft Visual C++®, as well as from interpreted languages such as Microsoft Visual Basic Scripting Edition or Microsoft JScript® The following table shows some of the OLE DB providers available from Microsoft and the data source with which they can be used Provider Data source Provider string Microsoft OLE DB provider for ODBC Any ODBC compliant data source MSDASQL Microsoft OLE DB provider for Microsoft Indexing Service Microsoft Indexing Service MSIDXS Microsoft OLE DB provider for Microsoft Active Directory™ Service Heterogeneous directory services through ADSI (including LDAPcompliant directory services and Novell NDS) ADSDSOObject Module 7: Universal Data Access with ADO 2.5 Provider Data source Provider string OLE DB provider for Microsoft Jet Microsoft Jet databases, such as those created with Microsoft Access Microsoft.Jet.OLEDB.4.0 Microsoft OLE DB provider for SQL Server™ Microsoft SQL Server databases SQLOLEDB Microsoft OLE DB provider for Oracle Oracle databases MSDAORA Microsoft OLE DB provider for Internet Publishing Data published in IIS Web sites or Windows 2000 Web folders MSDAIPP.DSO Microsoft OLE DB provider for OLAP Services Multidimensional data in a SQL Server OLAP Services database MSOLAP Through these and other providers, you can use OLE DB and ADO to access many different kinds of data throughout the enterprise Note The ADO library provides Automation objects, which allow diverse data sources to be manipulated by using a standard set of properties and methods Depending on the provider being used, some ADO properties and methods may produce inconsistent behavior or may not be supported ... objects to access Web-based data 2 Module 7: Universal Data Access with ADO 2.5 # Using ADO 2.5 ! Understanding OLE DB ! The ADO 2.5 Object Model ! Using ADO Objects ADO 2.5 is provided with Microsoft... guidelines and using efficient data access programming techniques v vi Module 7: Universal Data Access with ADO 2.5 Highlight some of the ways in which you can use ADO to access databases efficiently,... owners Module 7: Universal Data Access with ADO 2.5 iii Instructor Notes Presentation: 105 Minutes Lab: 60 Minutes This module describes how to use Microsoft ActiveX® Data Objects (ADO) 2.5 for universal