List box still loads data I don't want?

// Variables defined here...
Var rsData As RowSet = dbJobLogSp.SelectSQL( "SELECT * FROM tblTankLocations WHERE address=? ORDER BY status ASC, manufacture ASC", "18535 5th Ave" )
Var sStatus As String = rsData.Column( "status" ).StringValue

// Where the magic happens... or breaks...
lstBxTanks.RemoveAllRows
Try
  If( rsData <> Nil ) Then // So long as there is a record return it then close the rowset...
    For Each row As DatabaseRow In rsData
      If( sStatus = "Decommisioned" )Then
        // Do not a thing...
      Else
        lstBxTanks.AddRow( rsData.Column( "rNum" ).StringValue )
        lstBxTanks.CellTextAt( lstBxTanks.LastAddedRowIndex, 1 ) = rsData.Column( "serNum" ).StringValue
        lstBxTanks.CellTextAt( lstBxTanks.LastAddedRowIndex, 2 ) = rsData.Column( "manufacture" ).StringValue
        lstBxTanks.CellTextAt( lstBxTanks.LastAddedRowIndex, 3 ) = rsData.Column( "size" ).StringValue
        lstBxTanks.CellTextAt( lstBxTanks.LastAddedRowIndex, 4 ) = rsData.Column( "tankDate" ).StringValue
        lstBxTanks.CellTextAt( lstBxTanks.LastAddedRowIndex, 5 ) = rsData.Column( "status" ).StringValue
      End If
      sStatus = rsData.Column( "status" ).StringValue
    Next
  Else
    MessageBox( "What no records?!" )
  End If
  rsData.Close
Catch error As DatabaseException
  MessageBox( "Error: " + error.Message )
End Try

I don’t know why the record still loads when I explicitly tell it not to. This is driving me bonkers trying to sort this out! Linux Kubuntu 26.04 LTS using Sqlite as the DB.

A couple things that it could be…

You’re setting sStatus before the loop, and then again at the end of the loop. So you might be testing the previous record instead of the current one. Best practice is to set sStatus at the top of the for loop (especially since “for each” does not guarantee order).

Also “Decommissioned” may be spelled wrong in your code (it usually has two s’s). Depends how it’s entered in your database, obviously.

2 Likes

memory this status direkt after open the recordset make no sense, it is just the status of the first record.

and why not filter the status in the sql statement?

and status <> 'Decommisioned'

1 Like

I use instead a variable Row_Idx As Integer, then:


lstBxTanks.AddRow( rsData.Column( "rNum" ).StringValue )

Row_Idx = lstBxTanks.LastAddedRowIndex
lstBxTanks.CellTextAt( Row_Idx, 1 ) = rsData.Column( "serNum" ).StringValue

and so on.

“Faster“ to do and easier to read.

See how the sStatus has moved inside the loop?