I cannot figure out what is going wrong in this code. It is exactly the same as in other windows where I delete a listbox row, but in this window, I get the DB Error: near “5”: syntax error
What is wrong in this code? I am trying to get this fix for 2 days now.
Try
//Delete selected idea from database, then reload the data to the listbox
var index_selected as integer
LocationID_Selected = ListBoxStoryLocations.CellValueAt(ListBoxStoryLocations.SelectedRowIndex,1)
if index_selected >-1 then
app.db.ExecuteSQL("DELETE FROM Locations WHERE ID = " + LocationID_Selected)
else
MessageBox("Sorry, but there are NO Locations left to remove.")
end if
Catch error As DatabaseException
MessageBox("DB Error: " + error.Message)
//If the TABLE does not exist, you will get the **DB Error: near "5": syntax error**
End Try
//Refresh the listbox
RefreshLocationsListbox
End Select
Is LocationID_Selected an integer? If so, you need to add .ToString to it.
If not, I suggest you make a temporary variable like this:
if index_selected >-1 then
Var sql as string = "DELETE FROM Locations WHERE ID = " + LocationID_Selected
app.db.ExecuteSQL(sql)
else
MessageBox("Sorry, but there are NO Locations left to remove.")
end if
are you sure the Locations table exists?
are you sure LocationID_Selected is getting a valid ID?
are you using the correct db?
can you create a sample project/db to share so others can test?
Yes, the table exists, the Add Location code works correctly and shows up in the table.
You are right, this below code looks weird. I added that to see if there is a row selected, but that’s not the way to do this. I will change it. Thanks.
var index_selected as integer //this will be 0
...
if index_selected >-1 then
I figured it out. The variable LocationID_Selected was empty all the time and it looks like it’s because it was declared in both the Property of the window and in a Module. I didn’t know actually it was there. So I assume it was resetting the value all the time back to 0.