Private Sub DeleteEntry
Private Query As String
Private Answ As Int
'ask the user for confirmation
Answ = Msgbox2("Do you really want to delete " & edtFirstName.Text & " " & edtLastName.Text, "Delete entry", "Yes", "", "No", Null)
If Answ = DialogResponse.POSITIVE Then 'if yes, delete the entry
Query = "DELETE FROM persons WHERE rowid = " & Main.RowIDList.Get(Main.CurrentIndex)
Main.SQL1.ExecNonQuery(Query) 'delete the entry
Main.RowIDList.RemoveAt(Main.CurrentIndex) 'remove the rowid from the list
If Main.CurrentIndex = Main.RowIDList.Size - 1 Then 'if the current index is the last one
Main.CurrentIndex = Main.CurrentIndex - 1 'decrement it by 1
End If
ShowEntry(Main.CurrentIndex) 'show the next entry
ToastMessageShow("Entry deleted", False) 'confirmation for the user
ShowButtons
End If
End Sub
Private Sub ShowEntry(EntryIndex As Int)
Private RowID As Int
If Main.RowIDList.Size = 0 Then 'check if database is empty
Return 'if the database is empty leave the routine
End If
If Mode = "Add" Then
lblRowID.Text = ""
edtFirstName.Text = ""
edtLastName.Text = ""
edtCity.Text = ""
Else
Private ResultSet1 As ResultSet
RowID = Main.RowIDList.Get(EntryIndex) 'get the rowid for the given entry index
'read the entry with the given ID
ResultSet1 = Main.SQL1.ExecQuery("SELECT * FROM persons WHERE rowid = " & RowID)
lblRowID.Text = RowID 'display the ID
ResultSet1.NextRow
edtFirstName.Text = ResultSet1.GetString("FirstName") 'read the value of the FirstName column
edtLastName.Text = ResultSet1.GetString("LastName") 'read the value of the LasstName column
edtCity.Text = ResultSet1.GetString("City") 'read the value of the City column
ResultSet1.Close 'close the ResultSet, we don't need it anymore
End If
ShowButtons
End Sub