You were right.
I had no idea that I had to specifically add parameter objects
to the TQuery. I can't find any mention of this in any of my 4 Delphi
books.
My procedure is now as follows, but I still
get "Could not find object". Is the code that I have used to add
the parameter correct?
procedure RunPQuery(SQLFile: string);
begin with RSQuery do
begin Close;
Unprepare; SQL.LoadFromFile(HomeDir +
'\SQLFiles\' + SQLFile + '.SQL');
Params.CreateParam(ftDate, 'SaveDate',
ptOutput); ParamByName('SaveDate').AsDate :=
CurrentDate;
Prepare;
ExecSQL;
MainForm.Memo.Lines.Add('Done'); end;
end;
Tomorrow, I will build the SQL in my code - but its not as
nice.
Mark
----- Original Message -----
Sent: Wednesday, May 30, 2001 4:11
PM
Subject: RE: [DUG]: SQL and
Parameters
Maybe it cannot find an object because the query has
NO parameters (I cannot see where your code creates one). So maybe you need to
add (using CreateParam or otherwise) a Param Object to the datsets
Params (with the name "SaveDate", type Output (I think), ftdate) - before you
call prepare.
Mike
Have tried this change, now. No better. I
assume the question about Short Date Format is only relevant while I am
using the DateToStr format?
I think there must be something quitye fundamental, that I
have not passed on to you guys.
I assume that I can use a vanilla TQuery with no
properties set; and that setting the ParamByName is ALL I need to. (I
have also tried Params[0].AsDate := CurrentDate.)
Is there some other fundamental aspect that I may not be
aware of?
Mark
----- Original Message -----
Sent: Wednesday, May 30, 2001 3:22
PM
Subject: Re: [DUG]: SQL and
Parameters
Mark
Have you tried -
ParamByName('SaveDate').AsDate :=
CurrentDate;
as opposed to
ParamByName('SaveDate').AsString :=
DateToStr(CurrentDate);
What is your Short Date Format - dd/mm/yy or
mm/dd/yy?
DateToStr may not be giving you a valid date
for SQL
Why you would get "could not find object", I
don't know.
HTH
Mike
----- Original Message -----
Sent: Wednesday, May 30, 2001 10:03
AM
Subject: [DUG]: SQL and
Parameters
Hi
Using Paradox.
When I run the following SQL code (DocNos.Sql) using
the LoadFromFile method, things work fine;
Delete from DocketNos Where DocketNo in
( Select DocketNo from Dockets Where ForCode not in ( Select
distinct forcode from dockets where docketdate >
'03/31/2001'))
But when I try to parameterise it as follows, and with
the final line of the Sql file changed to :
where docketdate > :SaveDate))
then I get an error message "Could not find
object"
procedure RunPQuery(SQLFile: string);
begin with RSQuery do
begin
Close;
Unprepare;
SQL.LoadFromFile('DocNos.SQL');
ParamByName('SaveDate').AsString :=
DateToStr(CurrentDate);
Prepare;
Open;
MainForm.Memo.Lines.Add('Done'); end;
end;
Can any one see where I have gone wrong?
TIA
Mark
|