Module 8: Accessing a Database

50 416 0
Module 8: Accessing a Database

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Contents Overview 1 Accessing Data from a Text File Using the Tabular Data Control 2 Accessing Data From an XML Document 11 Database Access Interfaces 19 Processing Forms 28 Lab 8: Retrieving Data from a Database Using ASP 39 Review 44 Module 8: Accessing a Database 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, ActiveX, BackOffice, FrontPage 2000, Internet Explorer 5, Internet Information Server, MS-DOS, Notepad, and Windows 2000 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. Program Manager: Steve Merrill Development Lead: Basabjit Chakrabarty (NIIT) Instructional Designers: Sangeeta Nair, Vijayalakshmi Narayanaswamy (NIIT); Veena Nambier, Yatinder Walia (NIIT) Technical Contributors: Scott Swigart (3 Leaf Solutions); Gary Gumbiner (Great Barrier Technologies, Inc.) Graphic Artist: Scott Serna (Creative Assets) Editing Manager: Jennifer Linn Editor: Reid Bannecker Production Manager: Miracle Davis Production Coordinator: Linda Lu Cannon (The Write Stuff) Build Coordinator: Eric Wagoner Testing Lead: Eric Meyers Testing: Bryan Urakawa, Chris and Edward Lead Product Manager, Internet Services: Hilary Vandal Manufacturing Manager: Rick Terek Operations Coordinator: John Williams Manufacturing Support: Laura King; Kathy Hershey Lead Product Manager, Release Management: Bo Galford Group Manager, Courseware Infrastructure: David Bramble General Manager: Robert Stewart Module 8: Accessing a Database iii Instructor Notes This module provides students with an overview of accessing a database. It explains the Tabular Data Control and the XML data island. It also describes the two standard data access interfaces. Then, it explains the procedure to create a data source name. This module also explains the Database Results Wizard. Finally, it explains how to process input forms by using Active Server Pages. At the end of this module, students will be able to: ! Access data from a text file by using the Tabular Data Control (TDC). ! Navigate through records by using the methods of TDC. ! Access data from an XML document. ! Describe the data access interfaces. ! Create a data source name. ! Connect to a data source by using Active Data Objects (ADO) ! Process input form information by using Active Server Pages (ASP). 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, 1912A_08.ppt. ! Module 8, “Accessing a Database” ! Lab 8, “Retrieving Data From a Database Using ASP” Preparation Tasks To prepare for this module, you should: ! Read all of the materials for this module. ! Complete the lab. Presentation: 140 Minutes Lab: 60 Minutes iv Module 8: Accessing a Database Module Strategy Use the following strategy to present this module: ! Accessing Data From a Text File Using Tabular Data Control This topic provides an overview of tabular data control. First, explain how to bind a TDC to a table. Then, explain the methods provided by TDC to navigate through records. Then ask students to perform a practice on accessing data from a text file by using TDC. ! Accessing Data From an XML Document This topic provides an overview to XML data island. First, explain how XML represents structured data. Then, how to create an XML data island with the help of the example provided. Then ask students to bind an HTML table to an XML data island. ! Database Access Interfaces This topic provides an overview of the standard access interfaces and how to create a data source name. First, explain what is a database. Then, describe the two standard access interfaces namely, ODBC and OLE DB. Then, demonstrate the procedure to create a data source name on your computer. Then ask students to perform a practice on creating a data source name. ! Processing Forms This topic explains how to process input forms. First, explain how to work with HTML forms. Then, describe how to establish a connection by using ADO. Finally, explain how to process input forms by using ADO. Finally, this topic explains the methods to navigate records. Module 8: Accessing a Database 1 # ## # Overview ! Accessing Data from a Text File Using the Tabular Data Control ! Accessing Data from an XML Document ! Database Access Interfaces ! Processing Forms ! Lab 8: Retrieving Data from a Database Using ASP ! Review Every organization maintains data pertaining to its business, employees, and finances. This data needs to be accessed, maintained, and updated on a regular basis. This can be done by storing this information in a database. Many Web sites include data that is extracted from databases or data files. Data is extracted with the help of scripts, such as Active Server Pages that run on the Web server. These scripts use SQL statements to retrieve data from a database and then send the results in an HTML format for display in a client browser. Database technologies that run on the client are called client-side technologies. Client-side technologies return an HTML document along with a recordset to the server. The browser interprets the data and displays it to the user. The user can then work with the data without having to send queries to the server again. Two technologies that implement client-based database access are the Tabular Data Control and XML data islands. Server-side technologies, such as active data objects, have direct access to the data on the server and generate HTML pages. These HTML pages are then sent back to the client browser. After completing this module, you will be able to: ! Access data from a text file using the Tabular Data Control (TDC). ! Navigate through records using the methods of TDC. ! Access data from an XML document. ! Describe the data-access interfaces. ! Create a data source name. ! Connect to a data source using Active Data Objects (ADO) ! Process input form information using Active Server Pages (ASP). Slide Objective To provide an overview of the module topics and objectives. Lead-in In this module, you will learn how to access data from a database by using the tabular data control, XML data island, and FrontPage 2000. 2 Module 8: Accessing a Database # ## # Accessing Data from a Text File Using the Tabular Data Control ! Binding a TDC to a Table ! Navigating Records ! Practice: Using the Tabular Data Control TDC is a Microsoft ActiveX ® control that enables you to display the contents of a text file on a Web page. The text file is read locally, which minimizes server load and provides the user with a quick access. The data can be filtered or sorted by the browser using the properties and methods of TDC. TDC does not require a Web server component. When a Web page loads into a browser, the TDC makes a request for the text file. The text file on the Web server is cached locally by the browser. The data from the file is read into the TDC, and then displayed in the controls of a document. You can use a script to filter or sort the data on the client, with no server involvement. When reading data from a text file, you may have files in a format that need to be separated by a delimiter. A comma-separated file uses a comma (,) as its delimiter. TDC obtains data from a comma separated value file. The tables in a comma separated value file are in a text format. All fields are separated by commas. Slide Objective To provide an overview of the topic covered in the section. Lead-in After connecting to a data source, you can use the TDC to display the data on the Web page. Note Module 8: Accessing a Database 3 Binding a TDC to a Table ! Properties of TDC $ DataURL $ FieldDelim $ RowDelim $ TextQualifier $ Language $ UseHeader (View tdc.htm from Sampapps) <object classid= "clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" width="180" height="52" ID="flight"> <param name="FieldDelim" value=","> <param name="DataURL" value="source.txt"> <param name="Useheader" value="True"> </object> <object classid= "clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" width="180" height="52" ID="flight"> <param name="FieldDelim" value=","> <param name="DataURL" value="source.txt"> <param name="Useheader" value="True"> </object> Consider the Web site for a travel agency that provides services, such as checking flight availability and booking tickets, to its users. The Web site needs to provide information, such as the flight numbers and departure dates. The Web site consists of a table with two columns, flight number and date. If you want to display the table using HTML, the following code accomplishes this. <TABLE> <THEAD> <TR> <TD>Flight Number</TD> <TD>Scheduled Date</TD> </TR> </THEAD> <TBODY> <TR><TD>F001</TD> <TD>02/03/00</TD></TR> <TR><TD>F002</TD> <TD>02/05/00</TD></TR> <TR><TD>F003</TD> <TD>02/04/00</TD></TR> <TR><TD>F004</TD> <TD>02/05/00</TD></TR> <TR><TD>F005</TD> <TD>02/03/00</TD></TR> </TBODY> </TABLE> Creating a table in HTML involves a lot of code, which is inconvenient to edit or update. The table above can also be displayed by using a TDC control. Slide Objective To connect a TDC to a data source. Lead-in Properties of the TDC have to be set in order to connect to the Web server. Delivery Tip Open the file tdc.htm from \Inetpub\wwwroot\Sampapp s\Ch08 in Internet Explorer and show the results to the students. From the View menu, select Source and explain the code to the students. 4 Module 8: Accessing a Database To instantiate the TDC control, you need to use the <OBJECT> tag. The clsid attribute of the <OBJECT> tag is a unique ID assigned to the TDC control. The TDC control declaration is shown below: <object classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" width="180" height="52" ID="flight"> <param name="FieldDelim" value=","> <param name="DataURL" value="source.txt"> <param name="Useheader" value="True"> </object> The ID attribute allows you to refer to the TDC control later when writing scripts, and corresponds to the datasrc attribute. The datasrc attribute identifies the TDC and the datafld attribute specifies the name of a column in the text file that contains the data. The above table can also be displayed by using TDC control as shown in the following code: <TABLE DATASRC="#flight"> <THEAD> <TR> <TD>Flight Number</TD> <TD>Scheduled Date</TD> </TR> </THEAD> <TBODY> <TR> <TD><DIV DATAFLD="Flight Number"></DIV></TD> <TD><DIV DATAFLD="Scheduled Date"></DIV></TD> </TR> </TBODY> </TABLE> To connect the TDC to a text file, the following properties can be set: ! DataURL The DataURL property specifies the location of a file as a URL. The DataURL property is specified in the <OBJECT> tag for the TDC. However, changing this property after the page has been loaded causes the file to be loaded on the next reset event. ! FieldDelim The FieldDelim property identifies the character that is used to mark the end of the file. FieldDelim separates one data field from the next. The default character is a comma, but you can set the default to any other character. ! RowDelim The RowDelim property identifies the character used to mark the end of each row. RowDelim separates one data row from the next. The default value is the newline character, but you can set the default to any other character. ! TextQualifier The TextQualifier property is a single-character string that is used to surround fields that can include special characters, such as newlines, tabs, or commas. You can also use these special characters to delimit fields or rows. The default value is the double-quotation mark. Module 8: Accessing a Database 5 ! Language The Language property specifies the language used to create the file. By default, the value is English. ! UseHeader The UseHeader property is a Boolean expression that contains an initial line that names each column. By default, the value is False. If UseHeader is set to True, the first line of the data file should match the following syntax: fieldname:type, fieldname:type The fieldname variable is an arbitrary text string. The type variable can assume one of the following values. Value Description String Textual data (default) Date Calendar dates Boolean Logical data (Yes/No, True/False, 0/not 0) Int Integral numbers ( – 3, 1, 5) Float Floating-point numbers (3.141, 2.77, 0) 6 Module 8: Accessing a Database Navigating Records ! Nextpage() ! Previouspage() (View Navigate.htm from Sampapps) Sub btnnext_OnClick() mytable.Nextpage() End Sub Sub btnnext_OnClick() mytable.Nextpage() End Sub Sub btnprev_OnClick() mytable.Previouspage() End Sub Sub btnprev_OnClick() mytable.Previouspage() End Sub ! FirstPage() ! LastPage() You can create buttons in a document that enable users to navigate through the records of a recordset. This allows you to display only one record at a time. The methods that you can use to move from one record to another are: ! Nextpage() This method causes the next set of records to be displayed in a table. ! Previouspage() This method causes the previous set of records to be displayed in a table. ! Firstpage() This method causes the first set of records to be displayed in a table. ! Lastpage() This method causes the last set of records to be displayed in a table. Binding a table to a TDC control allows you to display multiple records at once. The table automatically creates as many rows as in the recordset. You can use the datapagesize attribute of the TDC control to limit the number of records displayed at one time. Slide Objective To provide an overview of the various methods for navigating through records. Lead-in You can limit the number of records displayed at one time by using the DATAPAGESIZE attribute. [...]... ODBC Database Simple Data Provider OLE DB Provider Non Mainframe Relational Data Data Database A database is a collection of data stored in a tabular form A database stores related data on a particular subject, such as tracking customer orders or maintaining employee information A database allows you to maintain a large amount of data in a structured way You can easily access, update, and delete data... Accessing a Database Connecting to a Data Source Slide Objective To connect to a data source Lead-in To access data from a database, you need to create a data source name A data source includes information, such as: ! The Database Management System (DBMS) the database uses ! The physical location of data ! The transport mechanism to access the data You define a data source by creating a data source name... from a database A Microsoft Access database contains tables, queries, forms, and reports to access data pages Data in linked tables may reside in another Access database, in an external data source such as Microsoft Excel, or in an ODBC data source such as Microsoft SQL Server™ A Microsoft Access database is saved with the extension mdb Database systems provide a driver that conforms to a standard database. .. Database- access interfaces are used for both accessing and writing data to a database Microsoft's database- access interfaces are designed to provide high performance access to information across an organization Database- access interfaces provide access to a variety of data and information sources that work with various tools and languages The standard database interfaces are: ! Open Database Connectivity... with a database FrontPage 2000 enables you to retrieve data from an ODBC-compliant database by using the Database Results Wizard and ASPs The first step is to create an ODBC data source You can import an Access database or you can connect to an Access database defined as a System Data Source Name on another server The data source informs the ODBC driver how to connect to the database After an ODBC data... Linking and Embedding Database (OLE DB) 20 Module 8: Accessing a Database Standard Database Access Interfaces Slide Objective To present the standard database interfaces Data Consumers ASP Page Other Applications ADO Lead-in To access data from a database, Microsoft provides interfaces, such as ODBC and OLE DB Visual Basic Application OLE DB Service Components Cursor Engine Query Processor Data Providers... created, FrontPage is used to add a database connection to the Web The database connection contains an ASP script that is required to access a database The Database Results Wizard window is shown in the following illustration: 26 Module 8: Accessing a Database Delivery Tip For this demonstration, you should have an existing data source name, MyDatabase ! Connect to a database 1 In FrontPage 2000, create... translates data queries of an application into commands that help access a database ODBC is an international standard for manipulating relational data using SQL query syntax across different data sources Module 8: Accessing a Database 21 Features of ODBC ! ODBC is SQL-based ! ODBC interface supports a broad range of tools ! ODBC has a plug-in model that simplifies implementation The disadvantage of using... database interface The standard database interfaces are ODBC and OLE DB ODBC ODBC is designed to allow access to relational database systems, such as Access and Oracle Most database systems provide an ODBC driver The driver provides the application with functionality to access a database In order to switch between databases, you need to switch the ODBC drivers Note A driver is a program that translates... Roberts Roberts 23500 23500 When an XML data island . from a database by using the tabular data control, XML data island, and FrontPage 2000. 2 Module 8: Accessing a Database # ## # Accessing Data from a Text. representation of data that enables precise declaration of content. Module 8: Accessing a Database 13 Using an XML Data Island ! An XML data island can be

Ngày đăng: 05/11/2013, 12:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan