Your Perfect Assignment is Just a Click Away

We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!


VBScript Database Query

VBScript Database Query

VBScript Database Query

VBScript Database Query Lab


‘ NAME: ComputersDatabase.vbs

‘ AUTHOR: jlmorgan ,

‘ DATE  : 8/19/2011

‘ COMMENT: Use 32 bit ODBC Microsoft Access Driver


recordsStr = “”

sqlStr = “SELECT * FROM Computers”

dataSource = “provider=Microsoft.ACE.OLEDB.12.0;” _

& “data source=C:\Scripts\Computers.accdb”

Set objConnection = CreateObject(“ADODB.Connection”)

objConnection.Open dataSource

Set objRecordSet = CreateObject(“ADODB.Recordset”)

objRecordSet.Open sqlStr , objConnection


‘ Display Headers

recordsStr = “Computer                 HostName           Room_Num” & _

”   CPU_Type  Speed   Num_CPUs   Bit_Size          OS_Type   ” & _

”      Memory       HDD_Size” & vbCrLf & _

“============================================================” & _

“=============================” & vbCrLf

Do Until objRecordSet.EOF

recordsStr = recordsStr & objRecordSet.Fields.Item(“Computer”) & _

vbTab & pad(objRecordSet.Fields.Item(“HostName”),12) & _

vbTab & pad(objRecordSet.Fields.Item(“Room_Num”),14) & _

vbTab & objRecordSet.Fields.Item(“CPU_Type”) & _

vbTab & objRecordSet.Fields.Item(“Speed”) & _

vbTab & objRecordSet.Fields.Item(“Num_CPUs”) & _

vbTab & objRecordSet.Fields.Item(“Bit_Size”) & _

vbTab & pad(objRecordSet.Fields.Item(“OS_Type”),12) & _

vbTab & objRecordSet.Fields.Item(“Memory”) & _

vbTab & objRecordSet.Fields.Item(“HDD_Size”) & vbCrLf





WScript.Echo recordsStr

function pad(ByVal strText, ByVal len)

pad = Left(strText & Space(len), len)

end Function


In this lab, students will complete the following objectives.

• Create a connection to an Access database.

• Create various SQL queries to extract information from a database.

• Format extracted data with column headers.

Element K Network Connections


For this lab, we will only need to connect to vlab-PC1. The computer vlab-PC1 is the computer on the left side while vlab-PC2 is on the right. If you leave the cursor on the PC icon for a few seconds, a tool-tip message will appear indicating the hostname of the PC. Open vlab-PC1 and log in as Administrator with the password password.

Lab Overview

Even though we are only using vlab-PC1 to complete our lab assignment, the database we will be accessing (Computers.accdb) is actually located on the computer vlab-PC2 in the directory C:\Database. This directory is shared as a ReadOnly network share by vlab-PC2. The Universal Naming Convention (UNC) name for this share is \\vlab-PC2\Database. Our VBScript program vlab-PC1 will have to open the \\vlab-PC2\Database share and map it to the local X: drive. The path specified fro the database will then be X:Computers.accdb.

The IT department maintains an Access database on vlab-PC2 that is used to inventory the computers in the various rooms. Fields in the database include: Computer Type, Hostname, Room Number, CPU Type, Number of Bits, Speed, Number of Processors, Operating System, Memory, and Hard Drive Size. We need to query this database to determine upgrades and replacements for existing computers.

Below (and on the following page) is a listing of the Computers.accdb database contents:




Task 1: Understanding the Net Use Commands in ComputerDatabase.vbs

• Open Notepad++. Use the menu option File/Open to open the VBScript program: C:\Scripts\ComputerDatabase.vbs.

Task 2: Understanding the ADODB.Connection and ADODB.Recordset Objects

• In NotePad++, look at the following code lines.

Line 11 contains the SQL Query String named sqlStr. This is the line you will have to modify to properly query the Computer database. The SQL Query “SELECT * FROM Computers” will select all fields from the database table Computers.


Lines 12 and 13 uses a string named dataSource to specify the Microsoft Driver and the name and location of the local database: X:Computers.accdb.


Line 14 Creates the “ADODB.Connection” object while line 15 opens the connection to the database.


Line 16 Creates the “ADODB.Recordset” object while line 17 provides access to the records using the SQL Query String and the Connection object. Line 18 moves the objRecordSet pointer to the first record.




Task 3: Displaying the Record Headers and Database Records


• In NotePad++, look at the following lines of the ComputerDatabase.vbs program.


Order Solution Now

Our Service Charter

1. Professional & Expert Writers: Writers Hero only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Writers Hero are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Writers Hero is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Writers Hero, we have put in place a team of experts who answer all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.