this is my first app with xojo
i have set a Shown event of a WebPage. This is the code:
rs is a RecordSet

  1. If rs <> Nil Then
  2. While Not rs.EOF
  3.   If rs.Field("type").StringValue = "table" Then
  4.     MsgBox("Table: " + rs.Field("name").StringValue)
  5.  End If
  6.   rs.MoveNext
  7. Wend
  8. Else
  9. MsgBox(“recordset vuoto, devi aggiungere records”)
  10. End If
  11. rs.Close
  12. App.db.Close

If i debug this whit step-by-step, i see that if rs is Nil (table of database not have row) the step jump to “Wend” and after jump to End.if (line 10).
The line 9 is not execute. Why?
Can you help me?

The RecordSet will not be nil if the database does not have the row. RecordSet will only be nil if there is an issue with your SQL statement. If the database does not have the row you are looking for the RecordSet.RecordCount will be 0.

My untested guess is that rs in your code is not actually nil.

As Tim said… a RecordSet can be in one of THREE states

  • NIL - usually due to an error in the SQL query that was executed
  • EMPTY (not to be confused with NIL). When the SQL query is VALID, but no results matched
  • NOT NIL, and NOT EMPTY - when the Query suceeded and returned one or more records

Be sure to check for database errors right after you execute the QUERY, and use THAT result instead of checking for NIL

If your RecordSet were nil, your app would crash at line 11.

Thank you!! I did not understand the meaning of Nil

“Nothing in there.”

no… “Nothing in there” is “EMPTY”
NIL means there is not even a “there”

It’s me who not digged deep enough. :slight_smile: