Link to home
Start Free TrialLog in
Avatar of Erik N
Erik N

asked on

SQL-statement..

What is wrong with the following:

  Query1.SQL.Add('SELECT * FROM DETAIL WHERE ID = :PARAM');
  Query1.ParamByName('PARAM').AsInteger:=Table1.FieldByName('ID').AsInteger;
  Query1.Open;



I get "Cannot find Parameter: Param"

Why ?

I haven't touched the properties, except for Datasource and DataBasename..
I also tried Query1.ExecSQL, but no difference..

/Thanx !
ASKER CERTIFIED SOLUTION
Avatar of guntherds
guntherds

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andybun
andybun

Query1.SQL.Clear;
Query1.SQL.Add('SELECT * FROM DETAIL WHERE ID = :PARAM');
  Query1.ParamByName('PARAM').AsInteger:=Table1.FieldByName('ID').AsInteger;
  Query1.Open;
Avatar of kretzschmar
hmm,

seems to be ok,
maybe you should give the param another name or
do a query.prepare before assigning the param like

Query1.SQL.Add('SELECT * FROM DETAIL WHERE ID = :PARAM');
Query1.Prepare;
Query1.ParamByName('PARAM').AsInteger:=Table1.FieldByName('ID').AsInteger;
Query1.Open;

meikl
Perhaps the type of ID is smallint,so you should write it as Query1.ParamByName('Param').AsSmallint:=....If it doesn't work either,You can write the statement as below:
 Query1.Params[0].AsInteger(Smallint):=...
 This will work absolutely!:-)
 
Just another option is not to use a parameter at all. If you already know which id you need, just used it in the query it self. It is faster.

Try :

Query1.sql.add('select * from Detail where id = ' + strToInt(Table1.FieldByName('id').asInteger))
Query1.open;

ok?
Avatar of Erik N

ASKER

The error was in the syntax:
SELECT * FROM DETAIL WHERE ID = : PARAM
was replaced by:
SELECT * FROM DETAIL WHERE ID = :PARAM

This seems to be a little sensitive..

Thanx, all of you !

/Erik N