How do I delete a row from the table example

alexdoan101

Member
Licensed User
Longtime User
1.) How do I delete a row for the the SQLTable4 example?

2.) How do i shift rows up and down in the SQLTable4 example ???
(like the Scrollviewlist example...this uses a list...)
 

Merlot2309

Active Member
Licensed User
Longtime User
Hello Alex
and welcome to the B4A community.

And a question:
Can you tell me how to delete a row from a table?
To be more specific:
User selects a row, presses the delete button and beside removing the row from the table, the record also has to be deleted from the sql-db.
The table row contains a unique id-field.
Until now I only got wrong results with RemoveAt :)BangHead: )

Thank you very much in advance.
Helen
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
Hi NJDude and thanks for your reply.

To be honoust SQL delete is not so much the problem.

On selecting a row in a table and pressing a Delete button the row has to be deleted (of course). I have an ID field in the table which is the key for the database record.
From a forum post I found RemoveAt but can't get it working.

Thanks in advance,
Helen.
 
Upvote 0

JMB

Active Member
Licensed User
Longtime User
Deleting row

Hi Helen

This is a real gash answer to what you want to do...

If you added a little bit of code which set a global variable ID to the Code of the last row selected, then you could use the following code to delete the last selected item from the database.

I've then used the subs ClearAll and ReadSQLTable to rebuild the table.

Sub DeleteSelectedItem

SQL1.ExecNonQuery("DELETE FROM table1 WHERE table1.Code = '" & ID & "'")​
ClearAll​
ReadSQLTable​
End Sub


The piece of code that sets the ID is added into the end of

Sub SelectRow(Row As Int)

......

ID=GetView(Row,0).Text

Hope this helps. It removes the last selected item from the database and from the table - albeit rather crudely. You can adapt as required for your database obviously.

JMB
 
Upvote 0

Merlot2309

Active Member
Licensed User
Longtime User
JMB and Klaus: thank you!

And Klaus: this was exactly what I was looking for.
Thought I had missed something but saw you just added this example today.
Thank you so much.

Helen.
 
Upvote 0
Top