[Gambas-user] Table doens't exist while saving data

Ron Onstenk ronstk at ...239...
Mon Aug 14 17:27:54 CEST 2006


On Monday 14 August 2006 15:54, Fabricio Silva wrote:
> *I'm trying to save data using class file instead of module. 
> So I have declared into the class global*
> 

What are you are tell exactly here?


> STATIC PUBLIC db AS NEW Connection
> PUBLIC CONST dbname AS String = "geral"
> PUBLIC CONST host AS String = "localhost"
> PUBLIC CONST passw AS String = "teste"
> PUBLIC CONST login AS String = "root"
> 
> *and the procedure to conect:*
> 
> STATIC PUBLIC FUNCTION conexao() AS Boolean
>   db.close
>   db.Type = "mysql"
>   db.Host = host
>   db.Login = login
>   db.Password = passw
>   db.Name = dbname
>   db.Open
> 
>   RETURN TRUE
> CATCH
>   RETURN FALSE
> 
> END
> 
Is the following also in that class* file?
Do specify clearly what you have, that is more easy
for others but special for you.

How many times I did this and solved many times the 
problem by doing that. I can't count.
Still I fail sometimes to do it myself correct :(


> *Then I used the code:*
> 
> PUBLIC global AS FrmPrincipal

Local variable global

> 
> PUBLIC SUB Form_Open()
>   ME.center
>   global = NEW FrmPrincipal

Hmm setting a global variable named 'global' with a Form

> END
> 
> *And Finally to save the data:*
> 
> PUBLIC SUB btnsol_Click()
> DIM db1 AS NEW Connection
> DIM dbname AS String
> DIM htable AS Result
> DIM comsql AS String
> 
>     SELECT CASE LAST.tag
>       CASE 1
>         db1.Close
>         dbname = "geral"
>         db1.Type = "mysql"
>         db1.Host = "localhost"
>         db1.Login = "root"
>         db1.Password = "teste"
>         db1.Open
>         db1.Begin
>         global.rs = db1.Exec("insert into `teste` values (&1)", txtteste)

Global is a form. Where is .rs comming from?
Second in db1 here there is no database selected (db1.name="pipo")
So no tables can accessed :)
 
> ....
> 
> *And the error: Table mysql.teste doens't exit*

That is true. See above

> 
> The table exist and I recreated it to make sure it's not wrong spelling.
> Someone have an ideal of what I am forgeting? Must be something like telling
> gambas wich table must I use?
> 
> tks
> 
> Fabricio
> 

Normal the logic is you assign in you form code.

  dim MyDB as Global
  dim rs as Result
		
  MyDB = new global()

  if MyDB.conexao() then
    rs = MyDB.Exec("insert into `teste` values (&1)", txtteste)
  else
    Print "Fabricio: panic"
  endif

You can find sample code parts in the help on the help site.


Ron

-- 
The only bug free software from MickySoft is 
still shrink-wrapped in their warehouse...




More information about the User mailing list