Hi all,
I just wanted to do a quick sanity check on the following code I currently use (DB + field names changed, code is otherwise identical).
Dim MyDatabase As New SQLiteDatabase
MyDatabase.DatabaseFile = GetFolderItem("MyDatabase.sqlite")
If MyDatabase.Connect Then
Dim MyRecordSet As RecordSet
MyRecordSet = MyDatabase.SQLSelect("SELECT * FROM <TableName> ORDER BY <FieldName>")
If MyDatabase.Error Then
MsgBox("Database error :" + Chr(13) + Chr(13) + MyDatabase.ErrorMessage)
MyDatabase.Close
Exit
End If
If MyRecordSet <> Nil Then
While Not MyRecordSet.EOF
listbox.AddRow(MyRecordSet.IdxField(1).StringValue)
MyRecordSet.MoveNext
Wend
Else
MsgBox("MyRecordSet = Nil")
End If
MyDatabase.Close
Else
MsgBox("Unable to connect to database")
End If
Does this look reasonable or could it be improved ?
Only thing I can think of right now is to possibly change the If… Then to something like this :
If MyDatabase.Error Then
MsgBox("Database error :" + Chr(13) + Chr(13) + MyDatabase.ErrorMessage)
MyDatabase.Close
Exit
ElseIf MyRecordSet <> Nil Then
While Not MyRecordSet.EOF
listbox.AddRow(MyRecordSet.IdxField(1).StringValue)
MyRecordSet.MoveNext
Wend
Else
MsgBox("MyRecordSet = Nil")
End If
MyDatabase.Close
Any thoughts folks ?
Thanks.