Listbox Population from DB

Hi there,
I am just starting with xojo and have an issue with the following code:

[code] Dim sql As String
Dim rs As RecordSet

sql = "SELECT * FROM accounts "
sql = sql + “ORDER BY name”
rs = MentorDatabase.SQLSelect(sql)

If rs <> Nil Then
accountsListbox.DeleteAllRows
While Not rs.EOF
accountsListbox.AddRow(rs.Field(“name”).StringValue)
accountsListbox.Cell(accountsListbox.LastIndex,1) = rs.Field(“opening”).IntegerValue
rs.MoveNext
Wend
End If[/code]

I am getting an error relating to accountsListbox.Cell(accountsListbox.LastIndex,1) which states:

There is more than one item with this name and it is not clear to which this refers

If I comment out that line then everything works as expected. Thanks in advance for your help.
Adam

The error message is somewhat misleading. Listbox cells take string values so you should be using

accountsListbox.Cell(accountsListbox.LastIndex,1) = str(rs.Field("opening").IntegerValue)

Thanks Dale. It is very misleading for a newbie :slight_smile:

Maybe less misleading…

accountsListbox.Cell(accountsListbox.LastIndex,1) = rs.Field("opening").StringValue

@Roger Clary - Dales answer was clear. I meant the error I was getting was misleading. The data in my db is stored as an integer so I am not sure your answer will work. I like Dales answer in that it is clear that the data is of type integer and simply being converted to string for the listbox requirements.

Yes, Adam, it will work. That’s what I wanted to point out to you. No matter how your data is stored in the DB, you can access it as an integer or a string. No need for the str(myInteger) conversion. Try it. It’s handy