Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
not able to access retrieved SQL results and is going to EOF
#1
Solved: 8 Years, 4 Months, 2 Weeks ago
Hi Guys,

Can anyone please tell the solution for the following problem...

basically i have select query which retrieves the results and i want to access the rest of my QTP script based on the query results.
i have the following piece of code in my script..

Code:
Set objDB = createobject("ADODB.Connection")
objDB.open("DSN=pqrDB;uid=abcd;pwd=xyz")
strQuery = "select   top 10  * from account"
Set objResults = objDB.Execute(strQuery)
msgbox objResults.Fields.count   ' returns value as 12 and is correct
[b]msgbox objResults.Recordcount   [/b]' returns value as -1 which is wrong

[i]Do Until objResults.BOF
  strEmpName   = objResults.Fields("empname")
  strEmpCode   = objResults.Fields("empcode")
  strEmpAccount  = objResults.Fields("empaccount")
  msgbox strEmpName & " " & " "& strEmpCode & " "& strEmpAccount
   objResults.MoveNext
Loop[/i]

objResults.Close
objDB.Close

Set objResults = Nothing
Set objDB = Nothing

till 5th statement script is running fine and giving correct results.
6th stmnt i.e msgbox objResults.Recordcount is returning value as -1
and its not at all going inside the DO until loop.

since the record count is returning as -1 its going to EOF and not at all executing the DO loop.

can anyone tellme why it is returning record count as -1 and suggest me how to proceed on this and its very important for me to proceed further and need it ASAP.


Thanks
navya
Reply
#2
Solved: 8 Years, 4 Months, 2 Weeks ago
please give me a clue to proceed on this ... stilll not able to figure out the problem...

atleast can anyone tell me how to find out the total number of rows retrieved from the sql query ??
Reply
#3
Solved: 8 Years, 4 Months, 2 Weeks ago
Dear Navya,

Please read the following post.
Good example on Database.
https://www.learnqtp.com/forums/Thread-DatabaseExample

You have to change the cursor type then only you can get correct record count.

Hope this helps you.
Reply
#4
Solved: 8 Years, 4 Months, 2 Weeks ago
Thank You very much Sridhar ..

but i was able to solve this problem by changing the database connection statement... dont know what the problem with earlier database connecting statemnet since it was able to retrieve cols but not rows... anyways..

and this is good and clear example of how to use cursor... and i tried using this example too and is running fine.

Thanks
Navya
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SQL Query Issue in QTP rajiv.qtp 1 2,527 11-28-2013, 10:36 AM
Last Post: Jay
  Exporting QTP runtime datatable to SQL server during SweetyChowdhury 1 3,291 05-10-2013, 03:41 AM
Last Post: sria123
  SQL on oracle database doesn't return a value Bluefields 2 3,329 07-09-2012, 01:23 PM
Last Post: Bluefields
  How to put retrieved results in an excel sheet padmini 1 3,206 09-30-2011, 09:13 AM
Last Post: rajpes
  How to fire SQL query on Excel sheet? shriqtp 6 16,763 08-06-2010, 11:39 PM
Last Post: QTPLearn

Forum Jump:


Users browsing this thread: 1 Guest(s)