Database connection help

Can anyone direct me to current and correct examples of how to connect to a database and Get data from specific fields? What little I could find in the language reference just gives me lots of errors.

I have been using Xojo since it was REALbasic 2, and haven’t updated for a few years, so I just downloaded the latest version to find half the language has changed. I am trying to write an application that will connect to a database and load data from specified fields into labels.

the eddie electronic example is up to date with the current xojo version, and has (almost) everything to do what you want.

1 Like

https://documentation.xojo.com/topics/databases/getting_started_accessing_databases.html

This sort of thing (Note: I left left out all error handling):

Var dbh As SQLiteDatabase, dbFile As FolderItem, reg as RowSet, myID as Integer

dbh    = new SQLiteDatabase
dbfile = new FolderItem ("/path/to/your/mydb", FolderItem.PathModes.Native)
dbh.DatabaseFile = dbFile

dbh.Connect ()

myID = 27

reg = dbh.SelectSQL ("select myfield from mytable where myID=?", myID)

myLabel.Text = reg.Column("myfield").StringValue

This assumes you have an existing database called mydb, with at least one table called mytable, at least two columns called myfield and myID, and at least one row in it.

Thank you everyone. With your help I got it working. Very much appreciated.