How do I pause a web app?

I have a listbox and I let the user delete row in the listbox which deletes the row in the table, then refreshes the rowset and the repopulates the listbox. The problem is, it is repopulating the listbox before the record gets deleted from the table. Here is the code.

var SQL As String
Session.db_Data.BeginTransaction
for x as Integer = 1 to lbUsersInGroup.RowCount
  
  if lbUsersInGroup.Selected(x-1) then
    SQL = "Delete from GROUP_USERS where ID = "+lbUsersInGroup.RowTagAt(x-1)
    Session.db_Data.ExecuteSQL(SQL)
  end
  
Next

Try
  Session.db_Data.CommitTransaction
  Populate_UsersInGroup()
  
Catch e As DatabaseException
  Session.db_Data.RollbackTransaction
end

How do I create a delay after the commit so the listbox doesn’t populate so quickly?

Try placing this after the db ops are settled (after the last end).

Kind regards, Andrew

The problem is, it is repopulating the listbox before the record gets deleted from the table.

How do you know? Dump the number of rows in the table to System.DebugLog before your for loop and immediately after CommitTransaction to confirm the rows are deleted and that it occurs prior to your call to refresh the list.

1 Like

These lines are problematic in my opinion. You should be using prepared statements here.

SQL = "Delete from GROUP_USERS where ID = ?”
    Session.db_Data.ExecuteSQL(SQL, lbUsersInGroup.RowTagAt(x-1).integerValue

More important though… you’re not removing the row from the listbox or (if you’re using a DataSource) refreshing the listbox.

As Greg said, using a prepared statement will be optimal.

As soon as you deleted the rows from the database, you don’t need to reload the entire listbox, just remove the affected rows with Listbox.RemoveRowAt

Make sure you loop from the end to the top:

for x as Integer = lbUsersInGroup.RowCount downto 1

If lbUsersInGroup.Selected(x-1) then

lbUsersInGroup.RemoveRowAt(x-1)
end
Next
3 Likes

I verified that the record was deleted before the Populate_UsersInGroup method was run to reload the listbox.

I thought of that last night as well, and this may be the best solution. Thanks for the reply.

Greg, thanks for the reply and your point is well taken. I will make appropriate changes.