SQL Data in Listbox

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
while not SQLDaten.EOF
Window1.Tabelle.AddRow( SQLDaten.Field(“BEN_ID”) )//this don’t work


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

Window1.Tabelle.AddRow( SQLDaten.Field(“BEN_ID”).stringvalue

No that doesn’t work :confused:

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

Is it wrong to put this in a Method?

No, this is wrong and cannot be compiled:

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 .

what exact error do you get ?

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

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.

what kind of database is it ?

Desktop App

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

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

I use:

Listbox1.AddRow ""

Everyday and it adds a Row.


[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.


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!

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

There is Data i saw an BEN_ID and a Name from the User ^^"

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

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


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 :frowning:

Read the LR page here if you want to make some positiv steps: 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.

[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.

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

ADDROW requires a string value