When there is only one element left, your call to first()
sets the cursor to that element, but then the next()
call in the while condition will return false, causing the exit from the loop and thus the deleteRow
won't be executed.
Use rs.beforeFirst()
`.
Note that your code has lots of issues, so get this answers as "for educational purposes" only.