Page 1 of 1

Add params programatically

Posted: Sat 14 May 2005 23:51
by Nidge
Hi,

I am looking to do the following below with corelab products...

Below is how I do it with TADO.

Query1.Parameters.CreateParameter('clientid', ftstring, pdInput,5,0);
Query1.Parameters.AddParameter;

with sql do
begin

Clear;

add('SELECT strClientId');
add('FROM [2001 Companies]');

add('Where clientid= :strClientId');

end;

Query.Parameters.ParamByName('clientid').Value := EDClientId.Text;

Posted: Mon 16 May 2005 08:49
by Ikar
With MyDAC you can do it easier:

Code: Select all

with Query.sql do
begin
   Clear;
     add('SELECT  strClientId');
     add('FROM [2001 Companies]');
    add('Where clientid= :strClientId');
end;

  Query.Params.ParamByName('clientid').AsString := EDClientId.Text;
So you needn't create parameters manually.

Posted: Mon 16 May 2005 23:41
by GEswin
I make a small correction, it should be strClientId as the parameter:

Code: Select all

Query.Params.ParamByName('strClientId').AsString := EDClientId.Text; 

Posted: Tue 17 May 2005 12:24
by kenny
It will work also if without the .params?
Query.ParamByName('strClientId').AsString := EDClientId.Text;
Is that a safty way?

Posted: Tue 17 May 2005 14:43
by Ikar
Yes