QTP script to connect to MS Access.

Explicit option

Dim with, rs

Set with = createobject (“adodb.connection”)

Set rs = createobject (“adodb.recordset”)

con.provider = “microsoft.jet.oledb.4.0”

con.open “d: testdata.mdb”

rs.open “select * from emp”, with

Do it while you are not rs.

VbWindow (“Form1”). VbEdit (“val1”). Set rs.fields (“v1”)

VbWindow (“Form1”). VbEdit (“val2”). Set rs.fields (“v2”)

VbWindow (“Form1”). VbButton (“ADD”). Click on

rs.movenext

Circle

The database we use here is MS Access.

In the above script I used a table called “emp” and column names like “v1” and “v2”.

“d: testdata.mdb” is the path of the table we created.

The main use of this script is to use test data from the table (which is in the database) in the application.

In the above script, we are passing values ​​from the database to the text boxes in the Windows application.

Similarly the script to connect to 2 other databases are

QTP script to connect to sqlserver.

Explicit option

Dim with, rs

Set with = createobject (“adodb.connection”)

Set rs = createobject (“adodb.recordset”)

con.open “provider = sqloledb.1; server = localhost;

uid = sa; pwd =; database = testdata “

rs.open “select * from emp”, with

Do it while you are not rs.

VbWindow (“Form1”). VbEdit (“val1”). Set rs.fields (“v1”)

VbWindow (“Form1”). VbEdit (“val2”). Set rs.fields (“v2”)

VbWindow (“Form1”). VbButton (“ADD”). Click on

rs.movenext

Circle

Script to connect to Oracle

Explicit option

Dim with, rs

Set with = createobject (“adodb.connection”)

Set rs = createobject (“adodb.recordset”)

con.open “provider = oraoledb.1; server = localhost;

uid = scott; pwd = tiger; database = testdata “

rs.open “select * from emp”, with

Do it while you are not rs.

VbWindow (“Form1”). VbEdit (“val1”). Set rs.fields (“v1”)

VbWindow (“Form1”). VbEdit (“val2”). Set rs.fields (“v2”)

VbWindow (“Form1”). VbButton (“ADD”). Click on

rs.movenext

Circle

This is the way you connect to the database in QTP and get the values ​​from the database.

Leave a Reply

Your email address will not be published. Required fields are marked *