[Gambas-user] Using DataSource et al

richard terry rterry at ...1946...
Tue Jul 22 01:34:48 CEST 2008


On Tue, 22 Jul 2008 07:53:16 am John K wrote:
> Hi,
> I'm new to Gambas so maybe I'm trying to run before I can walk. I'm in
> the process of writing an application which uses sqlite as its database.
> I've managed to create the database  and add data to its tables but now
> I want to read out the data using datasource, datacontrol & databrowser.
> I've scanned the Forum without any luck and have bought "A Beginners
> Guide to Gambas" but this doesn't cover this subject in any detail.
> Does anyone know where I can find a simple example, (maybe using Name,
> Registration Number & Date of Birth) which demonstrates the use of these
> tools or can help me in any other way?
> Thanks ........

You can also not use the data controls and do the whole thing manually, which 
I do. (last env was python, so I got used to doing it)

Maybe Benoit can criticise this if wrong, but what I do is:

Set up a global connection variable as I have dozens of forms accessing the 
database. Do the connection to the database (like in the data example in 
gambas Pass the queries to the database

This example is called from a textbox on a form which wants to get a list of 
person's occupations, so I pass the textbox and a listview to the routine. 
The occupations are pulled from postgres and populate the listview. You'll 
wonder why I make the listview's tag a textbox - its because my forms have 
dozens of textboxes, all using the listview, when the user selects from a 
popped up list, I use the tag to set other information.

I think the data controls built into gambas would do all this for  you, but 
manually:

Public Function occupation_get(tb As textbox, lv As listview)
  
   '-----------------------------------------------------------------
   'Retrieves a list of occupations from common.lu_occupations, load
   'them into a listbox whose key is pk_occupation
   'returns loaded listbox
   '-----------------------------------------------------------------
   sql = " SELECT * from common.lu_occupations WHERE occupation ILIKE '"
   sql = sql & Trim(tb.text) & "%' LIMIT 20"
   $Result = modDBConnect.exec_query(sql)
   lv.clear
   If $Result.count Then
      lv.tag = tb
      For Each $Result
             lv.Add($Result!pk, $Result!occupation)
      Next
      lv.Raise
      lv.Visible = True
   Else
      lv.Visible = False
   End If   
End 

Not sure if this helps, is confusing, but let me know


Richard
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge Build the coolest Linux based applications with Moblin SDK & win
> great prizes Grand prize is a trip for two to an Open Source event anywhere
> in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user






More information about the User mailing list