Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the return value of record set object,when value in data base does not exist?
#1
Solved: 10 Years, 8 Months, 4 Weeks ago
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
Reply
#2
Solved: 10 Years, 8 Months, 4 Weeks ago
Quote:how can i check that this value exists in databases or not?
use recordset.EOF this will return true if no data exists

Reply
#3
Solved: 10 Years, 8 Months, 4 Weeks ago
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.
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  General run error when Exist fails msacks 1 1,653 02-08-2019, 02:12 AM
Last Post: Ankur
  [UFT 12.52/VBScript] Test object exist, is visible and enabled before take an action sparkwanted 0 3,444 02-07-2017, 12:28 AM
Last Post: sparkwanted
  Childobject return wrong checkbox count.. VpnQTP 1 2,559 04-09-2015, 09:07 PM
Last Post: babu123
  how to find Excel file exist or not in vbscript code sree.85 3 10,794 08-22-2013, 11:42 AM
Last Post: akhandesh
  Remote server machine does not exist eroshan 5 13,916 05-06-2013, 06:03 PM
Last Post: Saket

Forum Jump:


Users browsing this thread: 1 Guest(s)