Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 07-02-2005
bor bor is offline
Registrado
 
Registrado: feb 2005
Posts: 2
Poder: 0
bor Va por buen camino
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.
Responder Con Cita
  #2  
Antiguo 07-02-2005
lucianojdg lucianojdg is offline
Miembro
 
Registrado: dic 2003
Posts: 42
Poder: 0
lucianojdg Va por buen camino
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
__________________
Luciano DG

Última edición por marcoszorrilla fecha: 07-02-2005 a las 15:35:56.
Responder Con Cita
  #3  
Antiguo 07-02-2005
lucianojdg lucianojdg is offline
Miembro
 
Registrado: dic 2003
Posts: 42
Poder: 0
lucianojdg Va por buen camino
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
__________________
Luciano DG

Última edición por marcoszorrilla fecha: 07-02-2005 a las 15:36:42.
Responder Con Cita
  #4  
Antiguo 07-02-2005
bor bor is offline
Registrado
 
Registrado: feb 2005
Posts: 2
Poder: 0
bor Va por buen camino
gracias luciano pero ya lo solucioné: el problema era que creaba el form dos veces.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 04:03:40.


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