Android Question Is it Possible delete a row in a sqlite database using a B4XTable?

Daniel44

Active Member
Licensed User
Hi everyone

I'm using a Erel's example to delete a row in a B4Xtable.. this one:

B4X:
Sub DeleteRow (tbl As B4XTable, RowId As Long)
   tbl.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array (RowId))
   Dim page As Int = tbl.CurrentPage
   Dim FirstIndex As Int = tbl.FirstRowIndex
   tbl.ClearDataView 'Updates the rows count.
   If FirstIndex + 1 >= tbl.mCurrentCount Then
       page = page - 1
   End If
   tbl.CurrentPage = page
End Sub

Usage example:

Code:

Sub B4XTable1_CellClicked (ColumnId As String, RowId As Long)
   Dim sf As Object = xui.Msgbox2Async("Delete row?", "Title", "Yes", "Cancel", "No", Null)
   Wait For (sf) Msgbox_Result (Result As Int)
   If Result = xui.DialogResponse_Positive Then
       DeleteRow(B4XTable1, RowId)
   End If
End Sub
That works fine.. Deletes a row from the B4XTable but only deletes the line in the BXTable but not in the sqlite database. Is it possible to delete a record in the database using the BXTable? Thank you
 

mangojack

Well-Known Member
Licensed User
Execute another query to also delete the db entry ... depending on what / how db records are loaded to the Table
the corresponding DB / B4X Table RowId might differ.

If this is the case, when initially loading the Table you could set the DB rowID to Label tag property, which could be read prior to table row deletion...
You would then have a reference to the same corresponding db row.

B4X:
Sub DeleteRow (tbl As B4XTable, RowId As Long, DBRowId As Long)
   SQL1.ExecNonQuery2("DELETE FROM MyDbTable WHERE id = ?", Array (DBRowId))
   tbl.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array (RowId))
   '..... more code
 
Top