May 12, 2011

Set a DataBase connection and run any queries from QTP

How to set a DB connection and to get a value from an "adodb" Data Base
Public Function DBSelect
set conn = createobject("adodb.connection")
conn.open "DSN=DSN_SERVERhere; UserID=userID; Password=password;"
set rs = createobject("adodb.recordset")
'get the date value from DB for an Event
rs.open "SELECT searchColumnHere FROM tableName WHERE columnName='value'", conn
eventsInDB = rs("searchColumnHere")
'eventsInDB = FormatNumber(eventsInDB, 2) - use this if you need to format the output nr
rs.close
DBSelect = eventsInDB 'here we are defining the output value
End Function