Micro Focus QTP (UFT) Forums
What is the return value of record set object,when value in data base does not exist? - 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: What is the return value of record set object,when value in data base does not exist? (/Thread-What-is-the-return-value-of-record-set-object-when-value-in-data-base-does-not-exist)



What is the return value of record set object,when value in data base does not exist? - Star - 08-26-2009

Hi,

I have a problem in recordset object, when result of query is null means no data in database. Following is my code:

Code:
Set Conn = CreateObject("ADODB.Connection" )
Conn.open "DRIVER={MySQL ODBC 5.1 Driver};SERVER=192.168.1.204;DATABASE=band;user id=monty;password=some_pass"
Set  recordSet = Conn.Execute( "select name, id, parentId from `Folders`  where name = 'test' and  parentId = 0 and id = 1;")

i m executing a query "select name, id, parentId from `Folders` where name = 'test' and parentId = 0 and id = 1;"
when this value exists in data base then my code is working fine.
But how can i check that this value exists in databases or not?
means if test in "name" colum does not exist then what would b the return value of recordset object? and how can we check that?

i did like following,
if recordSet = ""
if recordSet <> ""
if recordSet <> Nothing
if recordSet <> Null but these all are not working.

Please help me asap,

Thanks


RE: What is the return value of record set object,when value in data base does not exist? - Saket - 08-26-2009

Quote:how can i check that this value exists in databases or not?
use recordset.EOF this will return true if no data exists


RE: What is the return value of record set object,when value in data base does not ex - basanth27 - 08-26-2009

Saket solution will lead you to what you need. If you want to know the other way of finding wether it returned a value or not then you can try the below,

Code:
oCount = 0

While Not oRS.EOF
msgbox oRS.Fields.Item(1).Value
oCount = oCount + 1
oRS.MoveNext

Wend

msgbox oCount ' This will give you the total number of rows returned. if it 'has no rows then it will return zero.


On the Contrary you may try even this, This will give you the exact value returned from the RecordSet executed query.

Code:
Set oDB = CreateObject("ADODB.Connection")
Set oRS = CreateObject("ADODB.RecordSet")

oDB.Open("provider=Sqloledb;server=servername;user id=userid;password=serverpassword;database=defaultdb")

oRS.Open "Select * from person where Name ="&"'"basanth"'" ,oDB,3 ,4, 1
msgbox oRS.RecordCount ' If no record exist it will return 0. If a record exist or number of record exist then it will return the rows count.