Add params programatically

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Nidge

Add params programatically

Post by 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;

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

Post by 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.

GEswin
Posts: 186
Joined: Wed 03 Nov 2004 16:57
Location: Spain
Contact:

Post by 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; 

kenny
Posts: 43
Joined: Mon 15 Nov 2004 08:48
Location: Malaysia
Contact:

Post by 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?

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

Post by Ikar » Tue 17 May 2005 14:43

Yes

Post Reply