How to retrieve the data from database in qtp
Printable View
How to retrieve the data from database in qtp
Hi Rajaputra,
Create a connection to your database using the following code -
Set dbObj = CreateObject("ADODB.Connection")
dbObj.provider = :Name of Provider: - Microsoft Jet 4.0 incase of MSAccess
dbObj.connectionString = :Name of Sever:;UserID:username:;Pws=:password:;Initial_catalog = :DBName:
dbObj.Open
Set rsObj = createObject("ADODB.Recordset")
rsObj.open(dbObj)
rsObj.open "Select * from tablename where conditions"
set ar[1] = rsObj.fields(0)
The above line basically extracts field values and inserts them into an array for further use.
let me know if this helps -
Cheers.
Naweb and all, need help for the below code - got them somewhere on this site and modified for specific need... However, it has not been tested bucuase still have questions. Please focuss within the "select" and display data (last part) const adopenstatic = 3 const adlockoptimistic = 3 const aduseclient = 3 set objcon=createobject("adodb.connection") set objrec=createobject("adodb.recordset") ' establish connection - what shoud be for driver - give example? path? select case option case 1 objcon.open "driver={oracle in orahome92};server=oservername;uid=userid;pwd=upwd;dbq=database" case 2 objcon.open "driver={oracle in orahome92};server=oservername;uid=userid;pwd=upwd;dbq=database" case 3 objcon.open "driver={oracle in orahome92 (what shoud be here};server=oservername;uid=userid;pwd=upwd;dbq=database" case else msgbox("invalid ???.....") existtest end select objrec.cursorlocation = aduseclient -> what this is doing? ' fetch tempt uid objrec.open "select substr(body, instr(body, 'user id: ')+9, instr(body, 'password: ')) as id, substr(body, instr(body, 'password: ')+10, instr(body, '3. Follow')) as pwd from database.datable", objcon, adopenstatic, adlockoptimistic msgbox "result" & objrec.fields.item("id") & vbcrlf & objrec.fields.item("pwd") & vbcrlf ' flush out objrec.close objcon.close set objrec=nothing set objcon=nothing msgbox "executed sucessfully"