Populate ComboBox with SQLite Data...?

I’m completely new to using databases with XOJO.

Using SQLite, I created a database within XOJO, saved it to the app folder. When opening the database in XOJO I created a new table named categories. In the column section I added a test list of VarChar columns, Colum 1/2/3/4/ etc

In Xojo I want to be able to populate a Combobox with the Category columns in the database. Can anybody offer some help.?

Are-you able to write into the data base ?

Issue a SQLSelect for the Category Column to get a RecordSet,
In a loop, read that RecordSet,
Add Each entry string into the ComboBox

Not asked:
And at ComboBox Change time, make a Search on the data base to get the Record who hold the ComboBox string in the Category Column,
Then, display the contents from the RecodSet.

Simple to think, takes a little time to (understand and) implement.

@Panayiotis Yianni — It should look like:

[code]//DB is your Database, Combo is your ComboBox object and CategoryName is the field name for each Category’s name

dim RS as RecordSet = DB.SQLSelect( “SELECT * FROM Categories” )

Combo.DeleteAllRows

while not RS.EOF
Combo.AddRow RS.Field( CategoryName ).StringValue
RS.MoveNext
wend[/code]

in the open event of the combobox, read your database and fill the combobox with your values using combobox.addrow method.

I’m going wrong somewhere.

In the ComboBox open event I have this

[code]dim db as new Database
db = rememberdb
dim RS as RecordSet = db.SQLSelect(“SELECT * FROM General”)
ComboBox_Categories.DeleteAllRows

While not RS.EOF
ComboBox_Categories.AddRow RS.Field(“Genereal”).StringValue
RS.MoveNext
Wend[/code]

@Panayiotis Yianni — The value for “RS.Field” seems wrong. It should be the name of the column you want, not the name of the table! (and anyway it has an extra “e” to spell General). And that applies even if you have a single column.

“Genereal” is a vlid field?

Just go through the samples in xojo, there are some about SQLite

Ok, thanks all for your help so far but I still can’t figure it out.

This code:

Dim dbFile As New FolderItem Dim db As New SQLiteDatabase dbFile = GetFolderItem("database.sqlite") db.DatabaseFile = dbFile If db.Connect Then MsgBox("Connected") Else MsgBox("The database couldn't be opened. Error: " + db.ErrorMessage) End If

will simply check if the database exists. The database is in the same directory as the source but it errors saying the db doesn’t exist at that location but it is there

it will check IF the database is located next to the compiled exe
but note that when you compile an application and run it in debug the EXE is NOT necessarily where your db is any more (it may be in a sub folder etc)

Ahh. Ok, I put it in a sub folder called database and tried again and now I get a connection. phew. That’s out the way now. Now Lets see if I can do the rest from the help above.

Thank you all though for your kind assistance.

I really have to read up on how to populate a database. That’s where my knowledge lacks. Thank you all anyway. I seem to have things worked out for now.

Did you read: DatabaseRecord :

The example code is about inserting a New Record in the Data Base.

IMHO:
When I have to add a Data Base in a Project, I code Import (from text file) and Export (to a Text file).
Then, Run and create / file the data base using import (from text file).

Then, I save (or not) the db file and I can start back from the begining if something goes wrong.

And you have a data base file to “play” with (work with): add a Record, Delete a Record, navigation thru the data base Records, etc.

But, this is just me.