Simple QTP Script/code example of how to query an access database.
This is my tutorial on how to build a query that you can use in VBScript to extract information from a database.
The level of difficulty for this tutorial is beginner to intermediate.
You need to know basic VBScript syntax and need to have a copy of MS Access.
Code Starts from here:
dim objDB
dim objRS
dim intCounter
' create a database and recordset objects
Set objDB = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.RecordSet")
' configure the connection
objDB.Provider="Microsoft.Jet.OLEDB.4.0"
objDB.Open "c:\MyTestDatabase.mdb"
' count the number of records in the employee table
objRS.Open "SELECT COUNT(*) from Employee" , objDB
Msgbox "There are " & objRS.Fields(0).Value & " records in the employee table."
' destroy the objects
Set objDB = Nothing
Set objRS = Nothing
Post a Comment