Board index » delphi » adding a TQuery parameter add runtime

adding a TQuery parameter add runtime

Hi there,

I had a query containg a Parameter, but i wanted to make the query dynamic
by filling th eTQuery with a sql statment at runtime, but when you delete
the design time SQl you lose your paramters as well

Isd there a way to add a parameter to a query at runtime???

Thanx Rim

 

Re:adding a TQuery parameter add runtime


When you add SQL sentences to your new TQuery, params will be made by
itself.

Just use it like this..

Query1 := TQuery.Create(self);

Query1.DatabaseName := ..
and all the other settings..

//Query1.SQL.Clear;
Query1.SQL.Add('INSERT INTO COUNTRY (NAME, CAPITAL, POPULATION)');
Query1.SQL.Add('VALUES (:Name, :Capital, :Population)');

Query1.Params[0].AsString := 'Lichtenstein';
Query1.Params[1].AsString := 'Vaduz';
Query1.Params[2].AsInteger := 420000;

or
Query1.ParamByName('Name').AsString := 'Lichtenstein';
etc.

Query1.ExecSQL;

-Atle

Quote
Rim Ranshuijsen <ri...@hotmail.com> wrote in message

news:8ifm27$4km1@bornews.borland.com...
Quote
> Hi there,

> I had a query containg a Parameter, but i wanted to make the query dynamic
> by filling th eTQuery with a sql statment at runtime, but when you delete
> the design time SQl you lose your paramters as well

> Isd there a way to add a parameter to a query at runtime???

> Thanx Rim

Re:adding a TQuery parameter add runtime


Yes, but depends of how different queries you use.
TQuery recreates parameters whenever you modify SQL, just like at design
time. Whenever you modify SQL, surround the block with
SQL.BeginUpdate/SQL.EndUpdate. It will significantly improve performance, if
SQL has many lines and/or many parameters.
Two scenarios:
1. The new SQL is completely different: you simply change the SQL and new
parameters will be automatically created. Access them by name
2. The new SQL is just slightly different:
Query.SQL.BeginUpdate;
{change the SQL}
Query.SQL.EndUpdate;
Only now it recreates the parameters, so all parameters that reappear in new
SQL retain their properties (type, value,....). This works the same at
design time.

If the parameters never change (you allways have the same parameters in same
order whatever SQL is), you can set ParamCheck := false, so that parameters
are never recreated.
Example of this is if you just change the order clause.
--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.qwe.ce...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.

Quote
Rim Ranshuijsen wrote in message <8ifm27$4...@bornews.borland.com>...
>Hi there,

>I had a query containg a Parameter, but i wanted to make the query dynamic
>by filling th eTQuery with a sql statment at runtime, but when you delete
>the design time SQl you lose your paramters as well

>Isd there a way to add a parameter to a query at runtime???

>Thanx Rim

Re:adding a TQuery parameter add runtime


Hi!

The messages posted by Atle is right. By make sure your TQuery ParamCheck
property is set to true. When this property is set to true, it's autocreate
the params property when a query is created at runtime.

Ciao

VB

Other Threads