Database Connection in QTP

July 21st, 2009 by jigar.parvatia § 0

How to connect database with application running in QTP to check data in DB dynamically?

An example is shown connecting QTP with SQL Server

A simple script is shown below with necessary comments :

Dim con,rs,column_count,column_name,i,column_value

Set con=createobject(“adodb.connection”) // Its a connection object
Set rs=createobject(“adodb.recordset”) // A record set should be defined

// Necessary connection string should be their
con.open “provider=sqloledb.1;server=.\SQLEXPRESS;database=DBNAME;user id=XYZ;password=XYZ”

// Finally the record set is defined to fetch the value of particular fields according to the query passed.

rs.open”select * from tbl_newsMaster where username=’admin’”

// Checks the record set till the end until any record is found.If any record is found then it stores the values in “rs” record set.
Do while not rs.eof
For i = 0 To rs.Fields.Count -1
‘ msgbox rs.Fields.Count //counts the number of records in record set “rs”
column_value=rs.Fields(i).value //Fetches the value of particular field stored in record set “rs”
column_name=rs.Fields(i).name
Msgbox “Record Exist :” & column_name&” ” &column_value
next
rs.movenext
Loop

Tagged: , , ,

§ Leave a Reply

What's this?

You are currently reading Database Connection in QTP at Digicorp.

meta

Share