Record Count (SQLlite)

Hi Guys,
I am trying to populate a list box from a SQLlite db. I tried the following code but I only get one record on the listbox. Right now I have 8 records in the db. I also tried to use the RowSet.Rowcount so I can see it in a message box and it returns 1. I have the first code I tried rem out.

What am I missing. Can’t get the number of Rows

ProdListbox.RemoveAllRows

rs1.MoveToFirstRow
rs1.MoveToLastRow
vCount = rs1.RowCount
MessageBox vCount.ToString

If rs1 <> Nil Then
// Add the data from the table

//While Not rs1.AfterLastRow
//ProdListbox.AddRow("")

//For i As Integer = 0 To rs1.LastColumnIndex
//ProdListbox.CellValueAt(ProdListbox.LastAddedRowIndex, i) = rs1.ColumnAt(i).StringValue
//ProdListbox.RowTagAt(ProdListbox.LastAddedRowIndex) = rs1.Column(“ProdID”).IntegerValue
//Next

//rs1.MoveToNextRow
//Wend

While Not rs1.AfterLastRow
vProd = rs1.Column(“ProdNombre”).StringValue
vPrecio = rs1.Column(“ProdPrecio”).StringValue
ProdListbox.AddRow(vProd,vPrecio)
ProdListbox.RowTagAt(ProdListbox.LastAddedRowIndex) = rs1.Column(“ProdID”).IntegerValue
rs1.MoveToNextRow
Wend
End If

What is your query?

Hi Kem,
It is
var rs1 as RowSet = app.db.SelectSQL(“select * from Productos where ProdID = (select min(ProdID) from Productos)”)

Your query only returns one row, so row 1 is the last row.

1 Like

I feel so stupid. I added the code when I open the window and totally forgot I chose to select the first record. Thank you John, that pointed me to the right direction

wouldn’t

SELECT * FROM Productos ORDER BY ProdID ASC LIMIT 1

be more efficient? At the very least you would eliminate the need for a subquery.

1 Like

Hi Greg,
I ended up using:
var rs2 as RowSet = app.db.SelectSQL(“select * from Productos”)
and it returns all the records.

Thank You