Micro Focus QTP (UFT) Forums

Full Version: Retrieve the Data from Database
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I connect to database by code and imported data and placed in fields of application and validate some functionalities.... no problem up to here... when QTP tries to import second record from database... it is importing first record again... Can I know my mistake...?
Put your properly formatted code here.
Thank You Ankur, Now I am getting... No issues

Code:
Option Explicit
'On Error Resume Next
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")

con.open="Provider=SQLNCLI.1;Password=baba;Persist Security Info=True;User ID=Baba;Initial Catalog=baba;Data Source=MICROSOF-BBE3B6\SREE"
rs.open "select * from flight",con


Do until rs.eof
    invokeapplication "D:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
    Dim arr
    i=0
    arr=rs.fields("Userid")
    pwd=rs.fields("pwd")
    dialog("Login").Activate
    dialog("Login").WinEdit("Agent Name:").Set arr
    dialog("Login").WinEdit("Password:").Set pwd
    dialog("Login").WinButton("OK").Click
    If window("Flight Reservation").Exist Then
        reporter.ReportEvent micPass,"Valid Password","Flight Reservation Window Exists"
        else
        reporter.ReportEvent micFail,"InValid Password","Flight Reservation Window doesn't Exists"
    End If
    window("Flight Reservation").Close
    rs.movenext
Loop

rs.close
con.close

Set rs=nothing
Set con=nothing
Hi bfakruddin ,
I am trying same as you.
In this i am getting Login(Agent name) directly from database.
But when it comes to Password it says operation can not Performed.

See part of code is

Code:
arr=rs.fields("Login_name")
pwd=rs.fields("Pass")
dialog("Login").Activate
dialog("Login").WinEdit("Agent Name:").Set arr
Dialog("Login").WinEdit("Agent Name:").Type  micTab
dialog("Login").WinEdit("Password:").Set pwd

Here Agent Name get inserted from Database. But For Password field it says " Operation can not performed"
Can you pls help me.
as part of your code is correct........

check once you get a value from database whether it is retrieved from there or not....

use msgbox pwd
it will show whethet value has been retrieved or not... If it is not? I hope no chance because database has been already connected and got a Login_name,

check the column name is pwd or something else...

"Easy method to connect to any database" --> open new text file and save as "babaDB.udl"

one icon will appear at the text file location, double click on that and select your desired database and provide the user name password... navigation would be very simple, you can understand easily... give the info what it asks and close it...

Right click on that icon and open with "Note Pad"...

copy the available text and keep it in your code at the place of

con.open "copied text here"

'use it if you feel difficult to remember all the server,localhost, username, password... etc.,

;D
Hi bfakruddin ,
I placed 'msgbox pwd' , and its showing 'mercury'. it means it is getting properly.
But i think while inserting it is inserting something else.
What i guess is it is inserting ( space ) as extra string.Bcoz Login wondow says, Incorrect password.I also observed the extra element.
as for mercury(*******) there should be only 7 asterstiks. But what i observed is (********) i.e eight.
Even check that while Agent Name get inserted observe the Position of cursor,it is on the last position of that field.
I guess same thing may be happen for Password also.
What You say, if it , its real challange!
I stll not tried your second method,but first trying the first one.
Lets see....will get back you soon if solved.
if that is a case... that is not an issue buddy

use built-in function trim to ignore spaces
try this

Code:
arr=rs.fields("Login_name")
pwd=rs.fields("Pass")
dialog("Login").Activate
dialog("Login").WinEdit("Agent Name:").Set trim(arr)
Dialog("Login").WinEdit("Agent Name:").Type micTab
dialog("Login").WinEdit("Password:").Set trim(pwd)
Yes ! now it works. Thanks.

Can you please give me such built in function used in QTP ?
Or where i can found so that i can use them whereever necessay.
I have been trying this as for practice and I have found out that DSN=QT_Flight32 (Mercury flight reservation application) does not have any table containing Userid and Password information.

Code:
arr=rs.fields("Userid")
pwd=rs.fields("pwd")

OR

Code:
arr=rs.fields("Login_name")
pwd=rs.fields("Pass")[hr]
Option explicit
Dim con,rs

Set con = Createobject("ADODB.connection")
Set rs  =Createobject("ADODB.RecordSet")
        con.connectionstring="DSN=QT_Flight32;"
        con.Open
        con.commandTimeOut=7000
Set rs =con.execute("select * from flights")
msgbox rs.getstring


Do
invokeapplication "C:\Program Files\Mercury Interactive\QuickTestProfessional\samples\flight\app\flight4a.exe"

Dim  i
i = 0
user=rs.fields("Userid") 'does anyone know about the table which contains user id and pasword info
pwd=rs.fields("pwd")
dialog("Login").Activate
dialog("Login").WinEdit("Agent Name:").Set user
dialog("Login").WinEdit("Password:").Set pwd
dialog("Login").WinButton("OK").Click
window("Flight Reservation").Close
rs.movenext
Loop  until rs.eof

rs.close
con.close

Set rs=nothing
Set con=nothing
(02-16-2009, 12:07 PM)sudhirzpatil Wrote: [ -> ]Yes ! now it works. Thanks.

Can you please give me such built in function used in QTP ?
Or where i can found so that i can use them whereever necessay.

Built In function in QTP can be found under VB Script reference > VB Script > Reference > Functions
Pages: 1 2