Add params programatically

Add params programatically

Postby Nidge » Sat 14 May 2005 23:51

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;
Nidge
 

Postby Ikar » Mon 16 May 2005 08:49

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.
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Postby GEswin » Mon 16 May 2005 23:41

I make a small correction, it should be strClientId as the parameter:

Code: Select all
Query.Params.ParamByName('strClientId').AsString := EDClientId.Text;
GEswin
 
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain

Postby kenny » Tue 17 May 2005 12:24

It will work also if without the .params?

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


Is that a safty way?
kenny
 
Posts: 43
Joined: Mon 15 Nov 2004 08:48
Location: Malaysia

Postby Ikar » Tue 17 May 2005 14:43

Yes
Ikar
 
Posts: 1693
Joined: Thu 28 Oct 2004 13:56


Return to MySQL Data Access Components