Sunday, June 12, 2011

QTP Script to execute a SQL Query

Dim recordsetObj,commandObj
Dim connectionStr,queryStr

Set commandObj=createobject("ADODB.command")
Set recordsetObj=createobject("ADODB.recordset")
connectionStr="driver=sql server;server=papdsr05;database=test;uid=sa;pwd=sa"
queryStr="select * from employee"

commandObj.activeconnection=connectionStr
commandObj.commandtext=queryStr
Set recordsetObj=commandObj.execute
while not recordsetObj.EOF
empname=recordsetObj.fields("EmpName").value
recordsetObj.movenext
wend
'commandObj.close
recordsetObj.close

No comments: