SQLiteDatabase.DatabaseFile

From Xojo Documentation

Revision as of 13:41, 30 November 2021 by PLefebvre (talk | contribs) (Example: Added missing "End If" and fixed indentation.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Property (As FolderItem )
aSQLiteDatabase.DatabaseFile = newFolderItemValue
or
FolderItemValue = aSQLiteDatabase.DatabaseFile

Supported for all project types and targets.

Specifies the FolderItem for the SQLite database file. If DatabaseFile is Nil, calling the Connect method creates an in-memory database.

Example

This code connect to an existing SQLite database:

Var db As New SQLiteDatabase

Var dbFile As FolderItem = FolderItem.ShowOpenFileDialog("")

If dbFile <> Nil And dbFile.Exists Then
db.DatabaseFile = dbFile

Try
db.Connect
MessageBox("Connected to database successfully!")
Catch error As DatabaseException
MessageBox("DB Connection Error: " + error.Message)
End Try
End If

This code creates an in-memory database that you can use for storing temporary data:

Var db As New SQLiteDatabase

Try
db.Connect
// Create tables and add data as necessary.
Catch error As DatabaseException
MessageBox("DB Connection Error: " + error.Message)
End Try