Ver Mensaje Individual
  #1  
Antiguo 23-11-2007
identsoft identsoft is offline
Miembro
 
Registrado: abr 2006
Posts: 288
Reputación: 21
identsoft Va por buen camino
error en código?

Este código no funciona correctamente
Código Delphi [-]
procedure TfrmBancos.Button1Click(Sender: TObject);
begin
  SQLDataSet1.Close;
  ClientDataSet1.Close;
  SQLDataSet1.CommandText:= ' ';
  if (Length( edit1.Text) > 0)  then
     begin
       SQLDataset1.CommandText := 'SELECT * FROM BANCOS WHERE  NOM_BANCO LIKE :P_NBANCO';
       SQLDataSet1.ParamByName('P_NBANCO').AsString := Edit1.Text + '%'; 
     end
  else
     begin
        SQLDataSet1.CommandText := 'SELECT * FROM BANCOS ORDER BY   BANCO' ;
     end;
  Edit1.Clear;
  SQLDataSet1.Open;
  ClientDataSet1.Open;
end;
La primera vez lo hace correctamente. La segunda, si No introduces un texto en el edit1 (deberia hacer el else), arroja un error de que no existe el campo :P_NBANCO (que no es un campo de la bd sino un parámetro). Si introduces un texto, se queda como está, no sale el error pero no aparece nada.

y este otro sí
Código Delphi [-]
procedure  TfrmBancos.btnBancoClick(Sender: TObject);
begin
    SQLDataSet1.Close;
   ClientDataSet1.Close;
    SQLDataSet1.CommandText := '';
   if Length(edtBanco.Text)> 0  then
       begin
         edtBanco.Text :=  edtBanco.Text + '%';
          SQLDataSet1.CommandText := 'select * from bancos where nom_banco like '  +
             QuotedStr(edtBanco.Text);
       end
      else
       begin
          SQLDataSet1.CommandText := ' select * from bancos order by  banco';
      end;
    edtBanco.Clear;
   SQLDataSet1.Open;
    ClientDataSet1.Open;
end;
Los datos los saco a una grid.
Utilizo la BD es firebird 1.5 y Delphi 2006
No lo comprendo, ¿me podeis explicar que es lo que falta o qué estoy haciendo mal?
Responder Con Cita