Erro ao buscar dados no banco de dados - Delphi

Delphi

04/08/2018

Olá pessoal, tudo bem?

Bom, estou quebrando a cabeça a um tempo e estou travado para realizar uma consulta no firebird com o Delphi, o que eu estou tentando fazer é o seguinte, tenho um editText e nele eu vou digitar um código e pressionar a tecla enter, nisso, será disparado o evento KeyPress e após isso será consultado no banco de dados e preenchidos os demais campos, consegui fazer em uma tela, porém, em outra tela eu não estou conseguindo consultar... o erro que lança é o seguinte: "qrCRUD: Parameter ''''''''''''''''PROD_DESCRICAO'''''''''''''''' not found.";

Segue o trecho do código:

procedure TfrmMovimento.edtCodigoProdKeyPress(Sender: TObject; var Key: Char);
begin
if key = #13 then
begin
with DataModule1.qrCRUD do
begin
Close;
SQL.Clear;
SQL.Text := ''''''''''''''''SELECT * FROM TB_PRODUTO WHERE PROD_CODIGO = :COD'''''''''''''''';

ParamByName(''''''''''''''''COD'''''''''''''''').AsString := edtCodigoProd.Text;
Open;

edtDescricao.Text := ParamByName(''''''''''''''''PROD_DESCRICAO'''''''''''''''').AsString;
edtCodForn.Text := ParamByName(''''''''''''''''FOR_CODIGO'''''''''''''''').AsString;
edtUnidade.Text := ParamByName(''''''''''''''''UNIDADE'''''''''''''''').AsString;
edtEstoque.Text := IntToStr(ParamByName(''''''''''''''''PROD_ESTOQUE'''''''''''''''').AsInteger);
edtPreco.Text := IntToStr(ParamByName(''''''''''''''''PROD_PRECO'''''''''''''''').AsInteger);

end;
end;
end;

Agradeço desde já!
Matheus

Matheus

Curtidas 0

Melhor post

Luciano

Luciano

05/08/2018

Opa! Vi o erro:

Você está usando ParamByName para acessar um campo, que se acessa via FieldByname.

Troque os últimos comandos ParamByName por FieldByName e tudo funcionará.

Ex.:

edtDescricao.Text := FIELDBYNAME(''''''''''''''''''''''''''''''''PROD_DESCRICAO'''''''''''''''''''''''''''''''').AsString;
edtCodForn.Text := FIELDBYNAME(''''''''''''''''''''''''''''''''FOR_CODIGO'''''''''''''''''''''''''''''''').AsString;
edtUnidade.Text := FIELDBYNAME(''''''''''''''''''''''''''''''''UNIDADE'''''''''''''''''''''''''''''''').AsString;
edtEstoque.Text := IntToStr(FIELDBYNAME(''''''''''''''''''''''''''''''''PROD_ESTOQUE'''''''''''''''''''''''''''''''').AsInteger);
edtPreco.Text := IntToStr(FIELDBYNAME(''''''''''''''''''''''''''''''''PROD_PRECO'''''''''''''''''''''''''''''''').AsInteger);
GOSTEI 2

Mais Respostas

Matheus

Matheus

04/08/2018

Nossa, muito obrigado Luciano!!!! Funcionou certinho aqui!!
GOSTEI 0
Luciano

Luciano

04/08/2018

De nada! Disponha.
GOSTEI 0
POSTAR