Comp230 week 7 lab vbscript database query lab

Page 1

COMP230 Week 7 Lab VBScript Database Query Lab

Download here: http://homeworkfox.com/questions/computer-science/11718/comp23


Lines 20–24 display the Database fieldnames as column headers. Note the use of & to concatenate (add) string values together and _ which is the VBScript line continuation character. Lines 25–37 are a Do Until loop that sequences through the database looking for records that match the SQL Query String. The objRecordSet.EOF method checks to see if we have reached the last record in the database. This required because reading past the end of a database will cause an error.recordStr is a string variable initially set to “”. recordStr is used to create a multi-line string that contains the column headers and records that match the SQL query. The WScript.Echo recordStr statement in line 40 displays the column headers and records to the console or desktop windows depending on whether cscript or wscript is used to run the program. Lines 38 and 39 close the database connections made by the ADODB.Connection and ADODB.Recordset objects. The function pad(byVal strText, ByVal len) in lines 44–46 are used to format the field values with added spaces so the tab positions will line up correctly. Task 4: Write and Run Database Query Program 1 In this scenario, we need to query the Computer database to determine which computers need to be replaced. Our decision will be based on the CPU speed, Number of Processors, and the size of the Hard Drive.

Open the ComputerDatabase.vbs program in NotePad++ and Save As the program with the nameComputerReplace.vbs.

Modify the SQL Query String (sqlStr) in line 11 to extract the following information from the database.

Fields Displayed from Computers Table (specified by the SELECT clause). Computer Room_Num Speed Num_CPUs OS_Type HDD_Size Replacement Criteria (specified by the WHERE clause). Any computer with a single CPU Any computer with a CPU speed less than 2.1 GHz Any Computer with a Hard Disk Drive size less than 300 GBytes

Sort Criteria (specified by the ORDER BY clause).


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.