Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieve the Data from Database
#1
Solved: 10 Years, 9 Months ago
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...?
Reply
#2
Solved: 10 Years, 9 Months ago
Put your properly formatted code here.
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply
#3
Solved: 10 Years, 9 Months ago Smile 
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
Reply
#4
Solved: 10 Years, 9 Months ago
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.
Reply
#5
Solved: 10 Years, 9 Months ago Shy 
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
Reply
#6
Solved: 10 Years, 9 Months ago
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.
Reply
#7
Solved: 10 Years, 9 Months ago MyBB 
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)
Reply
#8
Solved: 10 Years, 9 Months ago
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.
Reply
#9
Solved: 10 Years, 9 Months ago
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
Reply
#10
Solved: 10 Years, 9 Months ago
(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
Want to fast track your QTP/UFT Learning? Join our UFT Training Course
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QTP Automation: How to retrieve Reporter.Reportevent Message scsenthil 1 5,262 11-14-2013, 07:51 PM
Last Post: spannerj
  How to retrieve ArrayList saved in Environment Variable Gautam26 8 4,462 11-07-2013, 08:26 PM
Last Post: ssvali
Exclamation Retrieve the complete height and width of a browser beyond the visible part as wel learnQtptips 0 2,017 05-22-2013, 09:36 AM
Last Post: learnQtptips
  How to retrieve a value from a table if the application is built in power builder. deepakmehta82 1 2,676 04-26-2013, 07:58 AM
Last Post: shaj
  Issue to use GetVisibleText to retrieve number from a PDF page in QTP11 jsun01 1 2,475 03-09-2013, 09:39 PM
Last Post: jsun01

Forum Jump:


Users browsing this thread: 1 Guest(s)