Micro Focus QTP (UFT) Forums
not able to access retrieved SQL results and is going to EOF - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: not able to access retrieved SQL results and is going to EOF (/Thread-not-able-to-access-retrieved-SQL-results-and-is-going-to-EOF)



not able to access retrieved SQL results and is going to EOF - navyasatish - 07-22-2008

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


RE: not able to access retrieved SQL results and is going to EOF - navyasatish - 07-23-2008

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 ??


RE: not able to access retrieved SQL results and is going to EOF - somisays - 07-24-2008

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.


RE: not able to access retrieved SQL results and is going to EOF - navyasatish - 07-24-2008

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