GARANTIR DESCONTO

Fórum O que tem de errado neste codigo? #264341

05/01/2005

0

Pessoal, o que ha de errado neste codigo? Quand oexecuto ele no Delphi., ele me retorna apenas 1 registro, porem quando executo o mesmo codigo no IB Expert ele me retorna o total de registro, mais de 10.

      cQuery2.SQL.Clear;
      cQuery2.SQL.Add(´select * from BOLETIM_NOTAS_FINAL´);
      cQuery2.SQL.Add(´where COD_BOLETIM = ´ + IntToStr(CodBoletim));
      cQuery2.Prepare;
      cQuery2.Open;
      j := 0;

      if DM.MemBoletimNotas.Active then
        DM.MemBoletimNotas.Active := False;
      DM.MemBoletimNotas.Active := True;

      ProgressBar2.Max := cQuery2.RecordCount;

      while not cQuery2.EOF do
      begin
        DM.MemBoletimNotas.InsertRecord([j,
          CodBoletim,
            cQuery2.FieldByName(´DESC_DISCIPLINA´).AsString,
            cQuery2.FieldByName(´N1´).AsString,
            cQuery2.FieldByName(´F1´).AsString,
            cQuery2.FieldByName(´N2´).AsString,
            cQuery2.FieldByName(´F2´).AsString,
            cQuery2.FieldByName(´N3´).AsString,
            cQuery2.FieldByName(´F3´).AsString,
            cQuery2.FieldByName(´N4´).AsString,
            cQuery2.FieldByName(´F4´).AsString,
            cQuery2.FieldByName(´TF´).AsString,
            cQuery2.FieldByName(´MA´).AsString,
            cQuery2.FieldByName(´MAX4´).AsString,
            cQuery2.FieldByName(´MR´).AsString,
            cQuery2.FieldByName(´MRX6´).AsString,
            cQuery2.FieldByName(´MF´).AsString
            ]);
        ProgressBar2.Position := Prog;
        Inc(Prog);

        Inc(j);
        cQuery2.Next;
      end;



nesta query
      cQuery2.SQL.Clear;
      cQuery2.SQL.Add(´select * from BOLETIM_NOTAS_FINAL´);
      cQuery2.SQL.Add(´where COD_BOLETIM = ´ + IntToStr(CodBoletim));
      cQuery2.Prepare;
      cQuery2.Open;


O CodBoletim, vem certo ou seja 1, 2 no caso...

entao se eu vou no IBExpert e uso
select * from BOLETIM_NOTAS_FINAL
where COD_BOLETIM = 1


Funciona perfeitamente... ja debuguei e vi que o valor da variavel CodBoletim é passado corretamente


entao o que pode estar acontecendo?


desde ja agradeco

[]s


Titanius

Titanius

Responder

Posts

05/01/2005

Titanius

Só acrescentando.. a cQuery2 eh criada em Runtime

var
 cQuery2: TIBQuery;
begin
  cQuery2 := TIBQuery.Create(FrmSelectAluno);
  cQuery2.Database := DM.IBDatabase1;
  cQuery2.Transaction := DM.IBTransaction1;

. . . 


[]s


Responder

Gostei + 0

05/01/2005

Bolus

Caro Colega,
Talvez a solução tenha passado despercebido, por sua preocupação...
No código informado,
      cQuery2.SQL.Clear; 
      cQuery2.SQL.Add(´select * from BOLETIM_NOTAS_FINAL´); 
      cQuery2.SQL.Add(´where COD_BOLETIM = ´ + IntToStr(CodBoletim)); 
      cQuery2.Prepare; 
      cQuery2.Open; 
      j := 0; 

      if DM.MemBoletimNotas.Active then 
        DM.MemBoletimNotas.Active := False; 
      DM.MemBoletimNotas.Active := True; 

      ProgressBar2.Max := cQuery2.RecordCount; 

      while not cQuery2.EOF do 
      begin 
        DM.MemBoletimNotas.InsertRecord([j, 
          CodBoletim, 
            cQuery2.FieldByName(´DESC_DISCIPLINA´).AsString, 
            cQuery2.FieldByName(´N1´).AsString, 
            cQuery2.FieldByName(´F1´).AsString, 
            cQuery2.FieldByName(´N2´).AsString, 
            cQuery2.FieldByName(´F2´).AsString, 
            cQuery2.FieldByName(´N3´).AsString, 
            cQuery2.FieldByName(´F3´).AsString, 
            cQuery2.FieldByName(´N4´).AsString, 
            cQuery2.FieldByName(´F4´).AsString, 
            cQuery2.FieldByName(´TF´).AsString, 
            cQuery2.FieldByName(´MA´).AsString, 
            cQuery2.FieldByName(´MAX4´).AsString, 
            cQuery2.FieldByName(´MR´).AsString, 
            cQuery2.FieldByName(´MRX6´).AsString, 
            cQuery2.FieldByName(´MF´).AsString 
            ]); 
        ProgressBar2.Position := Prog; 
        Inc(Prog); 

        Inc(j); 
        cQuery2.Next; 
      end;


acrescente a seguinte linha antes do while
      cQuery2.SQL.Clear; 
      cQuery2.SQL.Add(´select * from BOLETIM_NOTAS_FINAL´); 
      cQuery2.SQL.Add(´where COD_BOLETIM = ´ + IntToStr(CodBoletim)); 
      cQuery2.Prepare; 
      cQuery2.Open; 
      j := 0; 

      if DM.MemBoletimNotas.Active then 
        DM.MemBoletimNotas.Active := False; 
      DM.MemBoletimNotas.Active := True; 

      ProgressBar2.Max := cQuery2.RecordCount; 

      cQuery2.First;  <<<<<=============== Acrescente esta linha   ********
      while not cQuery2.EOF do 
      begin 
        DM.MemBoletimNotas.InsertRecord([j, 
          CodBoletim, 
            cQuery2.FieldByName(´DESC_DISCIPLINA´).AsString, 
            cQuery2.FieldByName(´N1´).AsString, 
            cQuery2.FieldByName(´F1´).AsString, 
            cQuery2.FieldByName(´N2´).AsString, 
            cQuery2.FieldByName(´F2´).AsString, 
            cQuery2.FieldByName(´N3´).AsString, 
            cQuery2.FieldByName(´F3´).AsString, 
            cQuery2.FieldByName(´N4´).AsString, 
            cQuery2.FieldByName(´F4´).AsString, 
            cQuery2.FieldByName(´TF´).AsString, 
            cQuery2.FieldByName(´MA´).AsString, 
            cQuery2.FieldByName(´MAX4´).AsString, 
            cQuery2.FieldByName(´MR´).AsString, 
            cQuery2.FieldByName(´MRX6´).AsString, 
            cQuery2.FieldByName(´MF´).AsString 
            ]); 
        ProgressBar2.Position := Prog; 
        Inc(Prog); 

        Inc(j); 
        cQuery2.Next; 
      end;


Isso deverá resolver o seu problema......
Espero ter ajudado.....


Responder

Gostei + 0

06/01/2005

Titanius

Valeu, agora está pegando todos os registros, porem o RecordCount ainda me retorna 1... mas de resto esta funcionando!

[]s


Responder

Gostei + 0

06/01/2005

Gandalf.nho

RecordCount não costuma funcionar direito com bancos de dados cliente-servidor como o IB/FB. Se você quiser o total de registros, terá que dar um FetchAll (não recomendado) ou usar SELECT COUNT(*) FROM tabela.


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar