Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   query - dbgrid refresh (https://www.clubdelphi.com/foros/showthread.php?t=18244)

bor 07-02-2005 02:05:35

query - dbgrid refresh
 
hola:

en un form tengo un query y dbgrid y en otro form modifico la tabla.
el problema es que las modificaciones no se actualizan en el dbgrid hasta que cierro los form y vuelvo a abrirlos.

este es el codigo

Código:

FClientes.QueryClientes.SQL.Clear;
        FClientes.QueryClientes.SQL.Add('insert into clientes');
        FClientes.QueryClientes.SQL.Add(' values (:codigo, :nombre, :dni, :nomb_comerc, :direccion;');
        FClientes.Queryclientes.ParamByName('codigo').AsString:= ECodigo.Text;
        FClientes.Queryclientes.ParamByName('nombre').AsString:= ECliente.Text;
        FClientes.QueryClientes.ParamByName('dni').AsString:= EDni.TExt;
        FClientes.QueryClientes.ParamByName('nomb_comerc').AsString:= Enombcomer.text;
        FClientes.QueryClientes.ParamByName('direccion').AsString:= Edirecc.text;
        FClientes.Queryclientes.ExecSQL;
        FClientes.QueryClientes.SQL.Clear;
        FClientes.QueryClientes.SQL.Add('select * from clientes');
        FClientes.QueryClientes.Close;
        FClientes.QueryClientes.Open;

ya lei en otros temas que la solucion era cerrar el query y volver a abrirlo pero no me funciona. tambien leí lo del query.refresh, pero tampoco me funciona.

si me podeis echar una mano os lo agradeceria

un saludo.

lucianojdg 07-02-2005 13:19:07

El problema es que no estas manejando bien las transacciones:Prueba con Esto:
// fDatos es un DataModule
// Server es el componente TDataBase

Código Delphi [-]
if fDatos.Server.InTransaction then    fDatos.Server.RollBack;
   
    fDatos.Server.StartTransaction;
   
   try FClientes.QueryClientes.SQL.Clear;
    FClientes.QueryClientes.SQL.Add('insert into clientes');
    FClientes.QueryClientes.SQL.Add(' values (:codigo, :nombre, :dni,
    :nomb_comerc, :direccion;');
    FClientes.Queryclientes.ParamByName('codigo').AsString:= ECodigo.Text;
    FClientes.Queryclientes.ParamByName('nombre').AsString:= ECliente.Text;
    FClientes.QueryClientes.ParamByName('dni').AsString:= EDni.TExt;
    FClientes.QueryClientes.ParamByName('nomb_comerc').AsString:=
    Enombcomer.text;
    FClientes.QueryClientes.ParamByName('direccion').AsString:= Edirecc.text;
    FClientes.Queryclientes.ExecSQL; fDatos.Server.Commit;
   
    except
      if fDatos.Server.InTransaction then
        fDatos.Server.Rollback;  MessageDlg('Se ha producido un error al intentar
   agregar el Cliente.', mtError, [mbOK], 0); 
    end;
    FClientes.QueryClientes.SQL.Clear;
    
    FClientes.QueryClientes.SQL.Add('select * from clientes');
     
    // FClientes.QueryClientes.Close; no es necesario cuando haces un clear
     
    FClientes.QueryClientes.Open;

Saludos

lucianojdg 07-02-2005 13:23:04

Perdón, no se que sucedio que quedo muy mal tabulado... lo reescribo para que sea legible.


El problema es que no estas manejando bien las transacciones:

Prueba con Esto:

// fDatos es un DataModule
// Server es el componente TDataBase
Código Delphi [-]
 if fDatos.Server.InTransaction then fDatos.Server.RollBack;
   fDatos.Server.StartTransaction;
 try 
   FClientes.QueryClientes.SQL.Clear; 
   FClientes.QueryClientes.SQL.Add('insert into clientes');     
   FClientes.QueryClientes.SQL.Add(' values (:codigo, :nombre, :dni, :nomb_comerc, :direccion;'); 
   FClientes.Queryclientes.ParamByName('codigo').AsString:= ECodigo.Text;   
   FClientes.Queryclientes.ParamByName('nombre').AsString:= ECliente.Text; 
   FClientes.QueryClientes.ParamByName('dni').AsString:= EDni.TExt; 
   FClientes.QueryClientes.ParamByName('nomb_comerc').AsString:= Enombcomer.text; 
   FClientes.QueryClientes.ParamByName('direccion').AsString:= Edirecc.text;   
   FClientes.Queryclientes.ExecSQL; fDatos.Server.Commit;
 except
   if fDatos.Server.InTransaction then
     fDatos.Server.Rollback; 
   
   MessageDlg('Se ha producido un error al intentar agregar el Cliente.', mtError, [mbOK], 0); 
 end;
 
 FClientes.QueryClientes.SQL.Clear;
 FClientes.QueryClientes.SQL.Add('select * from clientes');
 // FClientes.QueryClientes.Close; no es necesario cuando haces un clear
 FClientes.QueryClientes.Open;

Saludos

bor 07-02-2005 15:55:00

gracias luciano pero ya lo solucioné: el problema era que creaba el form dos veces.


La franja horaria es GMT +2. Ahora son las 14:13:26.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi