[Gambas-user] Database not working to select records, but fields/tables identified
Caveat
Gambas at ...1950...
Fri Jul 1 02:37:39 CEST 2011
Hi,
I'm trying to get database access to an ODBC datasource (have been
trying for a few days now).
I have the simplest Access (.mdb) database in the world: one table
called people, with an id, a first name, a last name, and a phone
number. There is no password on the database. I can see data in the
people table if I use MDB Viewer (i.e. the table 'people' is NOT
empty!).
Thanks to a tip from Ricardo, I have gotten as far as a good connection,
can see the ResultFields in the Result as expected (4 of them, with the
expected column names), I get the appropriate error if I deliberately
choose an invalid tablename (like persons for e.g.)... all good...
but...
I can't seem to get any kind of actual results in my result set,
Result.Available seems to always be False although I know there's data
in the table.
This is also the case if I run the Database example in Gambas3, so I'm
guessing it's not just my shoddy coding lol
Here's the code I used (but note **it doesn't work** with the Database
example either!):
Public Sub tryNewDB()
Dim conn As Connection
Dim res As Result
Dim sql As String
Dim resF As ResultField
conn = Connections["NEWDB"]
conn.Open
sql = "select * from people"
res = conn.Exec(sql)
For Each resF In res.Fields
Print "Found field: " & resF.Name
Next
Print "Result Count: " & res.Count
res.MoveFirst
Print "Available? " & boolToString(res.Available)
While res.Available
res.MoveNext
Print "Field1: " & res["Field1"]
Wend
End
Private Function boolToString(value As Boolean) As String
If value Then
Return "True"
Endif
Return "False"
End
************ result ***********
Found field: ID
Found field: Field1
Found field: Field2
Found field: Field3
Result Count: 0
Available? False
************ result ***********
Many thanks in advance for any new pointers...
Regards,
Caveat
More information about the User
mailing list