Connecting textfield with SQL database

So my next step in learning Xojo is to how to connect text fields with the database in my project.
In Filemaker it was a matter of double clicking a field and choosing the table you want it to connect to. What would be the way to do this in Xojo?

From what I read about it, I think I need to do something like an Update method when leaving the text field (using the LostFocus event handler on the field?), so the field.text property will be added to the row in the table that is already open at that moment, but I am not sure how to put all these puzzle pieces together yet. Any suggestions where to start?

In the “old” days, you would use BIND… but that is not recommended for a variety of reasons.

please detail EXACTLY what you wish to accomplish

I would use the various TextField events (Open, Lostfocus etc)… and would use pure SQL instead… it is safer

Ok. My app is for writing stories, so I start by clicking the Add Story button which starts a new record in the STORIES table. This lets me fill in the two Listboxes for the story title (STORIES table) and their characters (CHARACTERS table). That part is working.

Next I start to fill in the fields that have to be added to this record:
AuthorField (TextField)
GenrePopup (popupMenu)
Source (TextArea)
Notes (TextArea)

All the above fields have their fields in the STORIES table.

I assume the way to get this working is by adding the code to the Lostfocus, so when I click out of the field, the fields.text property will be added into the table fields?

That is one way… but it doesn’t really give the user an option of “canceling” any changes, or to “undo” a single change

Wouldn’t that be happening when he changes the text again and then leaving the text field?

wouldn’t WHAT be happening? or are you infering that any “cancel” or “undo” would involve the user entering the “old” data manually? that defeats the purpose of “undo” and “cancel”

I was thinking that if a user wants to edit the text, he could simply change it and the LostFocus open would update the field in the database table. That is how it works in Filemaker at least.

yes, but you still have no “undo”/“cancel” functionality

Well, those are things I can work on later. First I need to find a way to add the text field information to the database fields.

Usually, you work with several SQL queries at once:

  1. For the list you could have an SQL query that loads all your stories into a listbox.
  2. When you select a row in the listbox you have an SQL query to load the specific story into the TextArea.
  3. Then you need to have another SQL query to update the changed data from the TextArea into the database.