[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

SQL-statement..

Posted on 2000-03-10
6
Medium Priority
?
218 Views
Last Modified: 2010-04-04
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 !
0
Comment
Question by:Erik N
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Accepted Solution

by:
guntherds earned 400 total points
ID: 2605165
You must also add the PARAM-parameter to the Params-list of the query at run-time, then it will work

Gunther
0
 

Expert Comment

by:andybun
ID: 2605251
Query1.SQL.Clear;
Query1.SQL.Add('SELECT * FROM DETAIL WHERE ID = :PARAM');
  Query1.ParamByName('PARAM').AsInteger:=Table1.FieldByName('ID').AsInteger;
  Query1.Open;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2607492
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
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Expert Comment

by:sunsetyang
ID: 2607612
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!:-)
 
0
 

Expert Comment

by:evdzwan
ID: 2608396
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?
0
 

Author Comment

by:Erik N
ID: 2609256
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
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question