Retrieve row number based on value in DataTable - 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: Retrieve row number based on value in DataTable (/Thread-Retrieve-row-number-based-on-value-in-DataTable) |
Retrieve row number based on value in DataTable - marfa - 04-12-2011 Hi, I've got a DataTable and I need the script to search the DataTable, find a value in a particular column that matches the condition and retrieve a row number of that row which contains the searched value and run 1 iteration on the row number retrieved. Example, I want to run test on row which contains value = E in col2, so the result should be row number = 2 col1 col2 col3 A B C D E F G H I RE: Retrieve row number based on value in DataTable - Shrikantsr - 04-12-2011 Hi, you can run a For loop for the same purpose....Flow will be like this: 1.First get row count of the excel sheet with GetRowCount method. 2.Store it in a variable say Row_Count. 3.Run a For loop say "For i=1 to Row_Count 4.get the value of Coumn2 by "DataTabe.Value" method and store it in a variable say "Temp" 5.Compare the value Temp wiht value"E" and now u can run your test case accordinly... Hope it will be helpful.......... Regards RE: Retrieve row number based on value in DataTable - marfa - 04-12-2011 Thank you. So it would be like this? : Code: row_count = DataTable.GetRowCount How do I do the script stop after 1 run according to condition? I mean, the value (E) will be in more rows but I want to run it only on the first row that matches. RE: Retrieve row number based on value in DataTable - Shrikantsr - 04-12-2011 You can jump out of For loop once you are getting the expected value i.e "E" for you like this: If temp="E" Then Exit For Regards RE: Retrieve row number based on value in DataTable - PrabhatN - 04-12-2011 Marfa, Try out this: Code: getRow = Browser("YourBrowserName").Page("YourPageName").WebTable("TableName").GetRowWithCellText("E",2) // you can replace E and 2 with any string and number respectively Search "GetRowWithCellText" method in QTP help file. RE: Retrieve row number based on value in DataTable - basanth27 - 04-12-2011 Woah..not a advisable method to go with a webtable. This is a method which gets confused if it finds an E in any other row and will simply mislead you into a trap. Kind of a blind method when you have a webtable with minimal rows and not many conflicting data. Better to avoid this method. It is always advisable to loop through a webtable, retrieve the value, compare against your expected and when matched Exit the loop. RE: Retrieve row number based on value in DataTable - dharshinishankari@gmail.com - 07-31-2014 My issue is quite similar. I have a table with 2 columns (LoginName and Password) and 468 rows. I need to get the login name and password using a input box and on clicking login button. The system should verify if the login name and password is present in the table and only then allow to login. when i try executing the following code the loop is executed 468 times but exits unsuccessfully. Pls help. below is the code that i used. Code: Rowcount= DataTable.GetSheet("Global").GetRowCount Regards, |