[Gambas-user] Looking up data from a second table
Christof Thalhofer
chrisml at deganius.de
Tue Feb 20 01:47:09 CET 2018
Am 20.02.2018 um 00:03 schrieb T Lee Davidson:
> I think the DataSource should be set programatically.
For sure. This can be done easily in a module:
--8<-------------------------------------------------------------------
Property Read MyDB as Connection
Private $MyDB as Connection
Private Function MyDB_Read() As Connection
If Not $MyDB.Opened Then
With $MyDB
.Type = "postgresql" ' sqlite3, mysql
.Host = "hostname"
.Name = "dbname"
.Login = "username"
.Password = "password123456"
End With
Open($MyDB)
Endif
Return $MyDB
Catch
Error.Propagate
End
--8<-------------------------------------------------------------------
If you save this module with the name "DBs.module" then one can use the
connection anywhere in the program like so:
--8<-------------------------------------------------------------------
Dim Qry as String
Dim Res as Result
Qry = "select str from anything;"
Res = DBs.MyDB.Exec(Qry)
--8<-------------------------------------------------------------------
Or for a DataSource:
--8<-------------------------------------------------------------------
DataSource1.Connection = DBs.MyDB
DataSource1.Table = "select this from that;"
--8<-------------------------------------------------------------------
For the problem of the OP: I was not able to display the data in a
DataView. I do not understand how the DataView corresponds with the
DataSource, beecause I do not work with gb.db.form.
For my own programs I use my own component, which is able to display
database results in grids:
https://github.com/Deganius/gb.deg.form
Updating data in the database I do also programmatically by using the
events these – my own – components raise.
Alles Gute
Christof Thalhofer
--
Dies ist keine Signatur
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20180220/8708f44f/attachment.sig>
More information about the User
mailing list