Passagem de parametro para SQL

Delphi

14/09/2005

blz amigos,


Estou tentando passar valor do parametro para a propriedade SQL da query, eu criei um parâmetro “Cont” para a query, e especifiquei o tipo Data Type para ftString. Mas aparece uma mensagem de erro: (Query1: Parameter “Cont” not found). O código segue abaixo.

Query1.Active:= false;
Query1.SQL.Clear;
Query1.ParamByName(´Cont´).Value := Edit1.Text;
Query1.SQL.Add(´SELECT * FROM Country WHERE Continente = :Cont´);
Query1.ExecSQL;
Query1.Active:= true;


abraços
Pestana.


Pestana

Pestana

Curtidas 0

Respostas

Steve_narancic

Steve_narancic

14/09/2005

não sei se tem algo a ver mas inverta a posição das linhas:

Query1.ParamByName(´Cont´).Value := Edit1.Text;
Query1.SQL.Add(´SELECT * FROM Country WHERE Continente = :Cont´);


ficando assim
Query1.Active:= false;
Query1.SQL.Clear;
Query1.SQL.Add(´SELECT * FROM Country WHERE Continente = :Cont´);
Query1.ParamByName(´Cont´).Value := Edit1.Text;
Query1.ExecSQL;
Query1.Active:= true; 



GOSTEI 0
Steve_narancic

Steve_narancic

14/09/2005

eu particularmente faria assim:

with Query, SQL do
begin
 if active then Close;
 Clear;
 Add(´Select * from COUNTRY where CONTINENTE = :CONT´);
 Parambyname(´CONT´).AsString:= Edit1.text;
 open;
end;



GOSTEI 0
Rjun

Rjun

14/09/2005

Não entendi a presença do ExecSQL. Só o Open basta.


GOSTEI 0
Sandra

Sandra

14/09/2005

Complementando:
Não entendi a presença do ExecSQL. Só o Open basta.

Pestana,

Utilize o ExecSQL quando a instrução for Insert, Delete ou Update.


GOSTEI 0
Pestana

Pestana

14/09/2005

Primeiramente, agradeço pelo o tempo de resposta da mensagem.

deu certo, é só inverter a posição das linhas.
Rjun e Sandra vcs tem razão! foi erro meu quando estava digitando.

Ficou assim:

Query1.Active:= false;
Query1.SQL.Clear;
Query1.SQL.Add(´SELECT * FROM Country WHERE Continente = :Cont´);
Query1.ParamByName(´Cont´).Value := Edit1.Text;
Query1.Active:= true;


abraços
Pestana.


GOSTEI 0
POSTAR