Monday, January 31, 2011

How to connect Database in QTP?

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

No comments:

Post a Comment