Solved

SQL-statement..

Posted on 2000-03-10
6
215 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 100 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 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