Using a button “Add Name”, I am adding a name to a listbox while also adding it to a table in a database.
This was pretty straightforward.
I also have a “Delete Name” button that currently deletes the name entry from the listbox. I ALSO want it to delete the corresponding row in the database table.
When setting up the Add Name action, I was easily able to store the name typed by the user into a variable. Then take the variable and send it to the InsertRecord method for the database.
But with deleting a record I know I have to use an sql statement, and I’m unsure of how to get the selected row from the table into a way that I can use that in a query.
when you insert the record into the database, gzt back the rowid of that record you just created ( using lastrowid if using sqlite)
then store this rowid into the rowtag of the listbox current row .
then use the sql query delete from my_table where rowid_field=(the_rowid_stored_in_the_rowtag)
Hi. I am in a hurry, but here is a Snippet to start with deleting a Record from a Database.
Dim ps As PreparedSQLStatement
ps = Database.Prepare( "DELETE FROM TableName WHERE ID=?" )
ps.Bind( ListBox.RowTag( ListIndex ).IntegerValue, MySQLPreparedStatement.MYSQL_TYPE_INTEGER )
ps.SQLExecute
Or skip it all and go get ARGen and move on with your project. Dissecting ARGen will teach you a ton about ways to answer your question. But it would take years to learn how to do what ARGen already does out of the box. Buy it, use it. learn from it.
Well, I would caution against using ARGen without having a thorough understanding of how the Xojo database classes work first. Otherwise you’re trading one mystery for another and are no better off.
ARGen should not be used as a crutch in learning the Xojo database classes.