Micro Focus QTP (UFT) Forums
Problem with Data Table - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Problem with Data Table (/Thread-Problem-with-Data-Table--7646)



Problem with Data Table - Rakesh Sahukari - 10-14-2013

I am just giving some user credentials in data table and executing the flight application

My Data Table look likes below..

Username Password
---------- ---------
aaaaa mercury
bbbbb testing
ccccc mercury

Actually the scenario is to check with each of the user credentials & verify whether the user credentials are correct or not.

Below is my code...

Code:
InvokeApplication "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"

CntDtData=DataTable.GetRowCount

For i=1 to CntDtData
    Username1=DataTable.Value("Username",i)
    Password1=DataTable("Password",i)
        Dialog("Login").WinEdit("Agent Name:").Set(Username1)
    Dialog("Login").WinEdit("Password:").Set(Password1)
    Dialog("Login").WinButton("OK").Click
    If Window("Flight Reservation").Exist Then
        Reporter.ReportEvent micPass,"Flight Reservation","Login Successful for user:"&Username1
        Window("Flight Reservation").Close
        InvokeApplication "C:\Program Files (x86)\HP\QuickTest Professional\samples\flight\app\flight4a.exe"
     else
           Reporter.ReportEvent micFail,"Flight Reservation","Login Unsuccessful for user:"&Username1
        Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
    End If

Next
else
    Reporter.ReportEvent micFail,"Login Window","Login Window is not displayed"
End If

When I am executing the above code,I can able to verify the 1st user credential but after that I am geeting the run time error as 'Column Name Username does not exists'

Please find the attached screen shot regarding my error.


RE: Problem with Data Table - Sandeep81 - 10-24-2013

Hi,
You are getting this error because you are using i in place of sheetid. Since i is changing with every iteration, code is trying to fetch value from a column, in sheet i. You can omit using i and just give only the column name. The best way to do this is:

Code:
CntDtData=DataTable.GetRowCount
For i=1 to CntDtData
    DataTable.SetCurrentRow(i)
    Username1=DataTable.Value("Username")
    Password1=DataTable("Password")
........
........
.....
Next



RE: Problem with Data Table - Rakesh Sahukari - 10-24-2013

Thanks Sandeep.Its working fine..