Delete a Row from a Listbox ?

I may need a nap: I am stopped here.

I have a window where I display the contents of .sqlite files (each one have its own PushButton). I noticed that it will be a good idea to allow a Row delete (user errors in Add a Record; one field only for example).

I do not understand how to delete the Record Associated to a Row (I have the DB Unique ID in the last Column of each Row).

But as far as I understand RS.DeleteRecord have no parameter and the explanation let me as cold as ice :wink:

Imagine that I want to delete Row 6, how do I do that ?
In other words, how do I set the current Record (since this is the Record that will be deleted) ?

The example @ http://www.tutorialspoint.com/sqlite/sqlite_delete_query.htm

DELETE FROM table_name WHERE [condition];

talked to me, but I found the Xojo way and now I do not know; I am in front of a blackboard with a chalk in my hand, but I do not know what to write.

Help ! Hilfe ! Aiuto ! Au secours ! :wink:

Yes, some help is welcome.

db.sqlexecute(“delete from tablename where id=12345”)

Hi Tim (THANK YOU),

as simple as that ?

Doh ! It is not even Friday and I am already out of ideas…

Hello Emile

To show the records in your listbox, you have probably done something similar
your listbox

If I have the following fields as an example: Code, name, address, ID

On your SHOW button
Dim sql As string
sql = “SELECT code, name, address FROM names”
Execute the sql and assign it to a recordset
Then the contents of the recordset assign it to your Listbox

For i As integer = 1 To rs.RecordCount
ListBox1.AddRow (rs.Field (“code”). StringValue, rs.Field (“name”). StringValue, rs.Field (“address”). StringValue, str (rs.Field (“ID”). StringValue)
rs.MoveNext
Next

On your ELIMIAR button

It determines the column that is its ID in the ListBox1, for the example it is 3 (code is 0, name is 1, address is 2 and ID is 3)
The ID value of the selected row is assigned in varID

Dim varId As string = Listbox1.Cell (DataList.ListIndex, 3)

sql As string = “DELETE FROM names WHERE id = '” + varID + “’”
You execute the sql to delete the record

Again, make a new query and assign it to your Listbox, where the record will no longer be deleted

sql = “SELECT code, name, address FROM names”
Execute the sql and assign it to a recordset

For i As integer = 1 To rs.RecordCount
ListBox.AddRow (rs.Field (“code”). StringValue, rs.Field (“name”). StringValue, rs.Field (“address”). StringValue, str (rs.Field (“ID”). StringValue)
rs.MoveNext
Next

I hope you serve in something

regards
Raul

I do not saw that syntax :frowning: in the LR.

Thank you Raul.

It’s not part of Xojo, so you won’t find it in the LR. You’ll find it in the documentation for your database.

An this adds confusion to interrogation :wink:

Also, I started to be bored to always rebuild a .sqlite file (duplicate the file, run the project, check the new file, delete it and rename the duplicate OR run the project, check the modified file, delete it, create a new one and import the data from the txt original file). After doing that hunred of times, the process start to be an annoyance :frowning: