Real Software Forums
http://forums.realsoftware.com/

Nil Check for Recordset Not Working As Expected
http://forums.realsoftware.com/viewtopic.php?f=3&t=33270
Page 1 of 1

Author:  pipefile [ Mon Apr 05, 2010 6:23 pm ]
Post subject:  Nil Check for Recordset Not Working As Expected

I have a RecordSet checked to see if it pulled any information. Here is the code (boss told me to change the variable names to protect the innocent)

dim rs as recordset
dim SearchString as string

SearchString = "Select * from database_table WHERE column1 = 'info'"

rs = app.db.SQLSelect(SearchString)

if rs <> nil then
' Match - Do something here

else
' No Match - Do something else here

end if


rs will ALWAYS return Non-Nil, even if there is not a match to the query. The values in the RecordSet are Nil but the RecordSet itself isn't Nil

What would cause this behavior? I haven't run into this before.

Thanks.

Author:  timhare [ Mon Apr 05, 2010 7:23 pm ]
Post subject:  Re: Nil Check for Recordset Not Working As Expected

The only time the recordset will be nil is if there was an error in the query. Finding zero records is not an error. It will return an empty recordset, where rs<> nil and rs.EOF is already true.

Author:  rbasic20091005153 [ Mon Apr 05, 2010 10:20 pm ]
Post subject:  Re: Nil Check for Recordset Not Working As Expected

I agree with Mr. expert. rs=Nil or rs<>Nil will tell you if the database is accessible. Meanwhile, the following is what I happened to write to find out if there are data matches.

If rs.RecordCount>0 Then
// There's at least one match
Else
// There's no match
End if

Author:  timhare [ Mon Apr 05, 2010 10:53 pm ]
Post subject:  Re: Nil Check for Recordset Not Working As Expected

While RecordCount works well enough for RealSQLDatabase, it is hit or miss for the other databases. Testing EOF always works on all db's. Just fyi.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/