# SQL Data in Listbox

**URL:** <https://forum.xojo.com/t/sql-data-in-listbox/41795>\
**Category:** Databases\
**Created:** [January 26, 2018, 10:15am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795 "2018-01-26T10:15:38Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Patrick\_Lmmer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@Patrick\_Lmmer](https://forum.xojo.com/u/Patrick_Lmmer)\
**Post date:** [January 26, 2018, 10:15am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/1 "2018-01-26T10:15:38Z")

</div>

I have a Variable with SQL Data and how I can put that in a ListBox?

dim ODBC as new ODBCDatabase

ConnectionInfos = Globals.gInstanzVonODBC.GetConnectionInfos

ODBC.DataSource = ConnectionInfos

if ODBC.Connect then  
MsgBox “Verbindung konnte hergestellt werden”

SQLDaten = ODBC.SQLSelect(“SELECT BEN\_ID, BenutzerName FROM Benutzer”)

if ODBC.Error then  
MsgBox "Error: "+ODBC.ErrorMessage  
else  
while not SQLDaten.EOF  
Window1.Tabelle.AddRow( SQLDaten.Field(“BEN\_ID”) )//this don’t work

```
  SQLDaten.MoveNext
wend

```

end if  
else  
MsgBox "Error: "+ODBC.ErrorMessage  
end if

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [January 26, 2018, 10:16am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/2 "2018-01-26T10:16:59Z")

</div>

Window1.Tabelle.AddRow( SQLDaten.Field(“BEN\_ID”).stringvalue  
probably…

---

<div class="post-metadata">

**Author:** ![Patrick\_Lmmer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@Patrick\_Lmmer](https://forum.xojo.com/u/Patrick_Lmmer)\
**Post date:** [January 26, 2018, 10:50am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/3 "2018-01-26T10:50:43Z")

</div>

No that doesn’t work 😕

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 26, 2018, 11:07am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/4 "2018-01-26T11:07:42Z")

</div>

```auto
Window1.Tabelle.AddRow( SQLDaten.Field("BEN_ID").stringvalue, SQLDaten.Field("BenutzerName").stringvalue)
```

---

<div class="post-metadata">

**Author:** ![Patrick\_Lmmer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@Patrick\_Lmmer](https://forum.xojo.com/u/Patrick_Lmmer)\
**Post date:** [January 26, 2018, 11:13am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/5 "2018-01-26T11:13:27Z")

</div>

Is it wrong to put this in a Method?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 26, 2018, 11:26am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/6 "2018-01-26T11:26:06Z")

</div>

No, this is wrong and cannot be compiled:

```auto
Window1.Tabelle.AddRow( SQLDaten.Field("BEN_ID") ) // This don't work
```

Look ar the LR, how to get a .Field (Jeff and Jean-Yves already told you what to do, but read on your own) for your ODBCDatabase Database.

Link: [DatabaseField](http://documentation.xojo.com/index.php/DatabaseField) .

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 26, 2018, 11:43am UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/7 "2018-01-26T11:43:35Z")

</div>

> [@370834:@Patrick Lämmer](#):
>
> No that doesn’t work 😕

what exact error do you get ?

---

<div class="post-metadata">

**Author:** ![Jeff\_Tullin](https://forum.xojo.com/user_avatar/forum.xojo.com/jeff_tullin/32/693_2.png) [@Jeff\_Tullin](https://forum.xojo.com/u/Jeff_Tullin)\
**Post date:** [January 26, 2018, 1:22pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/8 "2018-01-26T13:22:28Z")

</div>

`dim s as string
s = SQLDaten.Field("BEN_ID").stringvalue
Window1.Tabelle.AddRow s
`

Now where is the error?  
Is BEN\_ID a number?  
Is the value NULL?

`dim s as string
s = format(SQLDaten.Field("BEN_ID").value, "0")
Window1.Tabelle.AddRow s
`

---

<div class="post-metadata">

**Author:** ![Patrick\_Lmmer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@Patrick\_Lmmer](https://forum.xojo.com/u/Patrick_Lmmer)\
**Post date:** [January 26, 2018, 2:40pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/9 "2018-01-26T14:40:52Z")

</div>

There is not rly an error when i put  
“Window1.Tabelle.AddRow( SQLDaten.Field(“BEN\_ID”).stringvalue, SQLDaten.Field(“BenutzerName”).stringvalue )” in the code but it doesn’t add a row.

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 26, 2018, 2:53pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/10 "2018-01-26T14:53:34Z")

</div>

what kind of database is it ?

---

<div class="post-metadata">

**Author:** ![Patrick\_Lmmer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@Patrick\_Lmmer](https://forum.xojo.com/u/Patrick_Lmmer)\
**Post date:** [January 26, 2018, 3:15pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/11 "2018-01-26T15:15:39Z")

</div>

Desktop App

---

<div class="post-metadata">

**Author:** ![Patrick\_Lmmer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@Patrick\_Lmmer](https://forum.xojo.com/u/Patrick_Lmmer)\
**Post date:** [January 26, 2018, 3:30pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/12 "2018-01-26T15:30:02Z")

</div>

or you mean that Database i want to connect to?  
That was a Filemaker Database

---

<div class="post-metadata">

**Author:** ![Jean-Yves\_Pochez](https://forum.xojo.com/user_avatar/forum.xojo.com/jean-yves_pochez/32/21769_2.png) [@Jean-Yves\_Pochez](https://forum.xojo.com/u/Jean-Yves_Pochez)\
**Post date:** [January 26, 2018, 3:49pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/13 "2018-01-26T15:49:03Z")

</div>

did you try to connect manually using any odbc tool to see if your sql query returns something ?

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 26, 2018, 4:05pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/14 "2018-01-26T16:05:49Z")

</div>

> [@370881:@Patrick Lämmer](#):
>
> it doesn’t add a row

I use:

```auto
Listbox1.AddRow ""
```

Everyday and it adds a Row.

Try:

[code]Dim LocRow As Integer

Listbox1.AddRow “”  
LocRow = Listbox1.LastIndex  
Listbox1.Cell(LocRow,0) SQL\_Value // 0 is for the example, SQL\_Value is the data that comes from your ODBC.[/code]

Now, you can check some values in the debugger: place a Berakpoint in your code and watch carefully what happens when you run, step by step your code.

HTH

---

<div class="post-metadata">

**Author:** ![Simon\_Berridge](https://forum.xojo.com/letter_avatar_proxy/v4/letter/s/cc9497/32.png) [@Simon\_Berridge](https://forum.xojo.com/u/Simon_Berridge)\
**Post date:** [January 26, 2018, 4:50pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/15 "2018-01-26T16:50:12Z")

</div>

Judging from your comments that a row is not being added, your original post showed these code lines:

`while not SQLDaten.EOF
  Window1.Tabelle.AddRow( SQLDaten.Field("BEN_ID") ) <----- This line
  SQLDaten.MoveNext
wend
`  
As a row was not added at all then I would suggest that the ‘while not SQLDaten.EOF’ is returning false, i.e. there is no data to show.

That would then NOT add a row at all!

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 26, 2018, 5:05pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/16 "2018-01-26T17:05:21Z")

</div>

```auto
 Window1.Tabelle.AddRow( SQLDaten.Field("BEN_ID").STRINGVALUE )    
```

---

<div class="post-metadata">

**Author:** ![Patrick\_Lmmer](https://forum.xojo.com/letter_avatar_proxy/v4/letter/p/77aa72/32.png) [@Patrick\_Lmmer](https://forum.xojo.com/u/Patrick_Lmmer)\
**Post date:** [January 26, 2018, 5:11pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/17 "2018-01-26T17:11:18Z")

</div>

There is Data i saw an BEN\_ID and a Name from the User ^^"

---

<div class="post-metadata">

**Author:** ![PaulS](https://forum.xojo.com/user_avatar/forum.xojo.com/pauls/32/199_2.png) [@PaulS](https://forum.xojo.com/u/PaulS)\
**Post date:** [January 26, 2018, 5:14pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/18 "2018-01-26T17:14:46Z")

</div>

Am I right to believe that BEN\_ID is an integer?  
If so, you can try to use IntegerValue instead of StringValue.

```auto
Window1.Tabelle.AddRow( SQLDaten.Field("BEN_ID").IntegerValue )
```

[http://documentation.xojo.com/index.php/DatabaseField.IntegerValue](http://documentation.xojo.com/index.php/DatabaseField.IntegerValue)

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 26, 2018, 5:18pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/19 "2018-01-26T17:18:53Z")

</div>

You will still be on the parking until you read the documentation and understand why Dave \* (read above) is correct. Without giving a Type (`.StringValue` for example) so the field knows what type the data is to be returned.

I do not even understand how this can compile ☹

Read the LR page here if you want to make some positiv steps: [http://documentation.xojo.com/index.php/DatabaseField](http://documentation.xojo.com/index.php/DatabaseField)

- and others.

AT LAST: imagine a second, even if you do not believe all advices people gave you here, go to the Xojo Example projects, ODBC folder (there are two projects) and make a search for `.Field(`. You will read the infamous `.StringValue` in that line.

---

<div class="post-metadata">

**Author:** ![DaveS](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@DaveS](https://forum.xojo.com/u/DaveS)\
**Post date:** [January 26, 2018, 5:26pm UTC](https://forum.xojo.com/t/sql-data-in-listbox/41795/20 "2018-01-26T17:26:13Z")

</div>

[quote=370917:@Paul Sondervan]Am I right to believe that BEN\_ID is an integer?  
If so, you can try to use IntegerValue instead of StringValue.

```auto
Window1.Tabelle.AddRow( SQLDaten.Field("BEN_ID").IntegerValue )
```

[http://documentation.xojo.com/index.php/DatabaseField.IntegerValue[/quote]](http://documentation.xojo.com/index.php/DatabaseField.IntegerValue%5B/quote%5D)  
ADDROW requires a string value

[Next page](https://forum.xojo.com/t/sql-data-in-listbox/41795.md?page=2)
