Hi @TheMexican,
query (Recordset) objects are intended for executing queries (SELECT
instructions) on a database, using a query to perform an INSERT
can lead to unexpected results as in your case. In your case it may really updates your db but the returned recordset is null so the query fires a DidFail
event instead of the DidFinish
event where you put the reload code.
The recommended way modify a DB is the following (please see the attached sample project ReloadTable.creoproject, it uses a SQLite DB but you can do the same with a MySQL DB):
1. Add a custom method to your Database object (in my example: addRow(name)
) and use the execute
method of the DB to perform an INSERT
instruction, you can add arguments to the custom method to specify dynamic values for your SQL instruction (in the example I use the argument name
). As the second argument of the execute
method I set the onSuccess
code that performs the reload of the table, for example:
var onSuccess = {
Window1.TableView1.reload(true);
}
var onError = {
Console.write("Error")
}
SQLite1.execute("INSERT INTO Table1 (Column1) values ('\(name)')", onSuccess, onError)
2. You can then use that method when you need to add a new value, in my example I use the following code in the Action
event of the AddButton:
SQLite1.addRow(TextField1.text)
P.S.: Another way to reload the table after the execution of the INSERT
instruction, instead of Window1.TableView1.reload(true);
, can be to re-run the Query (in my example SQLite1.Query.run();
). After the execution of a query (Recordset), all the controls that use the recordset as the configured Dataset will be reloaded. I use this way in the DeleteButton in the attached example.