Database retrieve Code Issue

Hi,
I am trying to write a retrieval script to check if my DB has a single entry, and if it does do something else. This is what i have at the moment

  Dim CheckData as new DatabaseQuery
  
  Dim sql as string
  
  sql = "select Mins from LockdownStore" // Mins (Column) / LocdownStore (Table)
  
  Dim isitreal as RecordSet = LockdownDB.SQLSelect(sql)  // running SQL request
  
  if isitreal.RecordCount = 1 then  // if there is info in the column then do something else do something else
    MsgBox "IS"
  else
    MsgBox "IS NOT"
  end if

The DB has an entry in the MINS column, but my code is returning that i do not have anything. Can someone point out to me what i am doing wrong please…

IF NOT RecordSet = NIL AND IF NOT RecordSet.EOF THEN // The RecordSet contains at least one record

HTH :slight_smile:

Hi Alex,

I’ve just tried to implement the above and it fails. Can you advise what i would swap out from the above to apply your answer… Thanks

[code] Dim DB As New Database
Dim SQL As String
DIM RS As RecordSet

//connect to your db here…
//…

//Now build the SQL
SQL = “select Mins from LockdownStore”

//Querying

RS = DB.SQLSelect(SQL)

IF RS <> NIL THEN
IF RS.EOF THEN
//There is no record
ELSE
//There is at least one record
END IF
ELSE //RS = NIL means something went wrong
IF DB.Error THEN
MsgBox DB.ErrorMessage
END IF
END IF[/code]

Untested and from the top of my mind :slight_smile:

Thanks Alex - Works a Treat Now! :slight_smile:

[quote=47097:@Alex von Siebenthal]IF NOT RecordSet = NIL AND IF NOT RecordSet.EOF THEN // The RecordSet contains at least one record

HTH :)[/quote]

I assumed each RecordSet should be closed, if it’s no longer needed. So i always use:

If RecordSet <>Nil Then If RecordSet > 1 Then ... EndIf RecordSet.Close EndIf

If i would use your code, i MAY get a NILObjectException, because i try to close a RecordSet that is NIL:

IF NOT RecordSet = NIL AND IF NOT RecordSet.EOF THEN ... ENDIF RecordSet.Close

Correct?

If you Dim the recordset as a local variable, you do not need to close it. It will be cleaned up, closed, and disposed of automatically.

Nice to know. Thank you Tim. :slight_smile: