Sorting a SQLite table

Hi guys,
This might be a simple question but for some reason I can not figure it out. I populate a ComboBox with a column from a SQLite table. I use the code below but for some reason, I can not get it to populate sorted ASC.

var rs as RowSet

Var sql as string
sql = “SELECT * FROM ShippingAddress ORDER BY CustName ASC”
rs = app.db.SelectSQL(sql)
rs.MoveToFirstRow

While Not rs.AfterLastRow
NameComboBox.AddRow(rs.Column(“CustName”).StringValue)
rs.MoveToNextRow
wend

Any ideas what am I missing or any pointers?
Thanks

Case-sensitivity issue? “bob” will come after “Charlie” when case is considered.

BTW, please wrap code in code tags to help us read it easier. You either use the toolbar when composing a message, or three backticks ("`") before and after the code block.

Thanks,
This is the data currently getting to the combobox
image

Not sorted at all

For debugging purposes, change your code slightly:

var value as string = rs.Column("CustName").StringValue
NameComboBox.AddRow(value)

Then set a breakpoint on that second line to see what value is as it’s coming from the database. Among other things, check the string encoding and see if there are any invisible characters.

If you can create a small project that recreates the issue, that would help a lot.

You know Kem, sometimes something this simple makes you pull your hair out. I did what you suggested by creating a small project and it sorted good. The problem was that I had forgotten I repopulate the list on GotFocus of the combobox and I totally forgot about that. Unreal.

Thank you very much for your help. It surely helped me resolve this issue.

1 Like

Glad to help. Please mark something as a “solution” if you’re satisfied.