https://foro.gambas-es.org/viewtopic.php?f=3&t=807&p=4506#p4506
-----------------------------------
techm3
Miercoles, 28 Julio 2010, 21:03

Re: No Puedo Añadir A La Base De Datos
-----------------------------------
La conexión está declarada en un botón de otro formulario con el cual se abre la que tengo. 

[code linenumbers=false syntax=gambas]PUBLIC SUB BtnData_Click()

  IF ConectarBase() THEN RETURN 
  FDataServices.RunNew(hConn)
  CerrarConexion()
  Form_Open()

END[/code]

La cuestión es que todo estaba funcionando bien, tal y como estaba, hasta hace dos días. De hecho el otro formulario que les comente aún sigue trabajando como está, no me ha dado problemas y la única diferencia entre los dos es a que columna irá la informacón y cuál es la info.

Comparto con ustedes ambos formularios por si acaso pasé por alto algo que si vean.  ;-) 


[b]El Que Funciona[/b]
[code linenumbers=false syntax=gambas]' Gambas class file

PRIVATE hConn AS Connection
PRIVATE Editando AS Boolean
PRIVATE hResul AS Result

PUBLIC SUB RunNew(Data AS Connection)
  
  hConn = Data
  ME.ShowModal()
  
END



PUBLIC SUB BtnCancel_Click()

  ME.Close()

END

PUBLIC SUB BtnAccept_Click()

  IF Editando THEN
    TRY hResul["title"] = TxtTitle.Text
    TRY hResul["collection"] = TxtCollection.Text
    TRY hResul["classification"] = TxtClass.Text
    TRY hResul["concentration"] = ComboConcentration.Text
    TRY hResul["format"] = ComboFormat.Text
    TRY hResul["comments"] = TxtComments.Text
    TRY hResul.Update()
  ELSE 

  TRY hConn.Exec("insert into movinfo values (&1,&2,&3,&4,&5,&6)", TxtTitle.Text, TxtCollection.Text, TxtClass.Text, ComboConcentration.Text, ComboFormat.Text, TxtComments.Text)
  
  ENDIF 
  
ME.Close()
  
  CATCH 
  Message.Error(Error.Text)
END

PUBLIC SUB RunEdit(Data AS Result)
  
  hResul = Data
  Editando = TRUE
  TxtTitle.Text = hResul["title"]
  TxtCollection.Text = hResul["collection"]
  TxtClass.Text = hResul["classification"]
  ComboConcentration.Text = hResul["concentration"]
  ComboFormat.Text = hResul["format"]
  TxtComments.Text = hResul["comments"]
  ME.ShowModal()
  
END

PUBLIC SUB Form_Open()

  IF Editando = TRUE THEN 
  ME.Title = "Editing..."
  ELSE 
  ME.Title = "Add to Database"
  ENDIF 
  ME.Move(FMain.ScreenX + (FMain.Width - ME.Width) / 2, FMain.ScreenY + (FMain.Height - ME.Height) / 2)

END[/code]

[b]Y El Que No Funciona[/b]

[code linenumbers=false syntax=gambas]' Gambas class file

PRIVATE hConn AS Connection
PRIVATE Editando AS Boolean
PRIVATE hResul AS Result

PRIVATE FUNCTION ConectarBase() AS Boolean
  
    IF hConn <> NULL THEN RETURN FALSE
    
    hConn = NEW Connection
    
    hConn.Host = "localhost"
    hConn.Name = "amp"
    hConn.Type = "MySQL"
    hConn.login = "root"
    hConn.Password = "nadielosabe71"
    TRY hConn.OPEN()
    IF ERROR THEN 
      hConn = NULL
      Message.Error(Error.Text) 
      RETURN TRUE
    ENDIF 
    
      RETURN FALSE
    END 

PUBLIC SUB RunNew(Data AS Connection)
  
  hConn = Data
  ME.ShowModal()
  
END

PUBLIC SUB MFecha(fecha AS Date)
TxtDay.Text = fecha
END

PUBLIC SUB DateChooser3_Change()
MFecha(DateChooser3.Value)
END

PUBLIC SUB BtnCancel_Click()

  ME.Close()

END

PUBLIC SUB BtnAccept_Click()

IF Editando THEN
     hResul["time"] = ComboTime.Text
     hResul["place"] = TxtPlace.Text
     hResul["applicant"] = TxtApplicant.Text
     hResul["equipment"] = ComboEquip.Text
     hResul["level"] = ComboLevel.Text
     hResul["schooloffice"] = ComboSchool.Text
     hResul["comments"] = TxtComments.Text
     hResul["status"] = ComboStatus.Text
     hResul["serviceDay"] = TxtDay.Text
     hResul.Update()
  ELSE 
     ConectarBase()
     hConn.Exec("insert into services values (&1,&2,&3,&4,&5,&6,&7,&8,&9)", ComboTime.Text, TxtPlace.Text, TxtApplicant.Text, ComboEquip.Text.ComboLevel.Text, ComboSchool.Text, TxtComments.Text, ComboStatus.Text, TxtDay.Text)
  
  ENDIF 
  
ME.Close()
  
  CATCH 
  Message.Error(Error.Text)
  
END

PUBLIC SUB RunEdit(Data AS Result)
  
  hResul = Data
  Editando = TRUE
  ComboTime.Text = hResul["time"]
  TxtPlace.Text = hResul["place"]
  TxtApplicant.Text = hResul["applicant"]
  ComboEquip.Text = hResul["equipment"]
  ComboLevel.Text = hResul["level"]
  ComboSchool.Text = hResul["schooloffice"]
  TxtComments.Text = hResul["comments"]
  ComboStatus.Text = hResul["status"]
  TxtDay.Text = hResul["serviceDay"]
  ME.ShowModal()
  
END

PUBLIC SUB Form_Open()

  IF Editando THEN 
    ME.Caption = "Editing..."
  ELSE 
    ME.Caption = "Add Service"
  ENDIF 
  
  ME.Move(FMain.ScreenX + (FMain.Width - ME.Width) / 2, FMain.ScreenY + (FMain.Height - ME.Height) / 2)

END
[/code]


