[Gambas-user] Database access

Thomas Boose gambas at ...267...
Sun Sep 28 11:08:53 CEST 2003


Op zo 28-09-2003, om 08:39 schreef Bernard PRE:
> hi,
>  
> I'm trying to find e very simple samples for accessing database :
>  
> Open a database
> Accessing a table
> Reading a field
> Updating / Deleting a record
> Close
>  
> Thanks for your help
>  
> Bernard
>  
Hi Benard,

I was playing around yesterday for the first time in gambas.
I made a little subroutine to load the root items of a 
treeview from a table.I will skip the uninteresting parts 

----------
PUBLIC SUB LaadDingen()
   DIM MyConn AS NEW connection
   DIM MyResult AS result

   WITH MyConn
      .Type = "mysql"
      .Host = "localhost"
      .Login = "YOURDBLOGIN"
      .Password = "YOURDBPWD"
      .Name = "YOURDBNAME"
      .Open
      myresult =  .Exec("SELECT id, Name " & 
                        "from TblDingen")
   END WITH

   WHILE MyResult.Available 
      TvwDingen.add (MyResult["id"], MyResult["Name"])
      MyResult.MoveNext
   WEND

CATCH
  Message.Error(Error.Text)
END
------------

You can use the same Exec() methode to delete and update 
values. 

Greetings Prutser





More information about the User mailing list