Re: ADO Database error regarding parameters
"Edward Diener" <
XXXX@XXXXX.COM>writes
.
Quote
If I am using parameters, but have colons in literal strings, turning
ParamCheck on will lead to errors.
How is that? If your using parameters, it doesn't matter what is in the
literal string. Kind of the point of using parameters.
Example:
At design time, use a TADOCommand component and set the CommandText to..
Insert into TheTable
(TheText, TheDate)
Values
(:TheText, :TheDate)
Make sure the (Object Inspector->Parameters property editor) Parameters are
configured correctly.
In Delphi code..
{some datamodule}
private
public
function InsertTheText(const TheText :String; const ADate :TDateTime)
:Boolean;
end;
function TMyDatamodule.InsertTheText(const TheText :String; const
ADate:TDateTime) :Boolean;
begin
with qInsertText do
begin
try
Parameters.ParamByName('TheText').Value := TheText;
Parameters.ParamByName('TheDate;).Value := ADate;
Execute;
Result := True;
except
on E:Exception do
begin
Result := False;
end;
end
end;
end;
Now any Form or Datamodule can use this function..
{some on click event}
if MyDatamodule.InsertTheText(Memo1.Text, DatePicker1.Date) then
Showmessage('Yippee, it worked!')
else
ShowMessage('Oh {*word*99}, back to the newsgroups');
Quote
Of course if I manipulate my code to
check for colons in literal strings, and then replace the literal values
with parameters, I will be OK but that is much work to do to check all
my literal values for colons. So I do not think it is nearly as simple
as you think,
You are correct, that is why no one does that on purpose. Using VCL
parameters works, and works very well and why most C/S developers use them.
Good luck,
krf