7

in a certain scenario, i was trying to use the select query inside QTP (More specifically QTP Using VB script) But the code is not working.

Option Explicit
Dim con,rs
Set con=createobject("adodb.connection")
Set rs=createobject("adodb.recordset")

con.open "Driver={Microsoft ODBC for Oracle};Server=myServer; Uid=USERNAME;Pwd=PASSWORD;"
rs.open "SELECT B.STATUS FROM STUDENT B WHERE B.BATCHCODE='FIRST' ",con

Do while not rs.eof
DataTable.GlobalSheet.AddParameter.RawValue = rs.fields("v1")
rs.movenext
Loop

Release objects
Set rs= nothing
Set con= nothing

Please help me knowing which section of the code is getting script result fail.

Girish
  • 157
  • 1
  • 1
  • 16
  • Is the problem in the query or in the `DataTable`? Have you tried using a vbs file to see if the problem is related to UFT? – Motti Oct 01 '14 at 08:38
  • Comment not clear.. can you elaborate?? or let me know if u need some more input from my end. (I'm new to UFT and VB scripting) – Girish Oct 06 '14 at 06:58
  • What is not working? Try to isolate the minimal code that doesn't work, then see if it's UFT specific or a problem with your VBS code. You can do this by putting the code in a .vbs file and executing it. – Motti Oct 06 '14 at 09:07
  • okiee, I'll try the same and let u know... thanks in advance :) – Girish Oct 06 '14 at 09:35
  • okiee... i have tried debugging the code, and the problem starts from the following line: `con.open "Driver={Microsoft ODBC for Oracle};Server=myServersIPAddress; Uid=USERNAME;Pwd=PASSWORD;"` also, i have added a watch for the same and found that there are 2 objects in the Error Tab for variable con. – Girish Oct 08 '14 at 06:13

1 Answers1

17

"Item cannot be found in the collection corresponding to the requested name" - this error comes when the field is not present in the recordset which you are trying to refer to!

rs will not have "v1" and it has only "STATUS".

  rs.fields("v1")

So, it should be

rs.fields("STATUS")
vins
  • 15,030
  • 3
  • 36
  • 47