paramters and like

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ccmcbride
Posts: 101
Joined: Tue 01 May 2007 16:36

paramters and like

Post by ccmcbride » Thu 15 Nov 2012 00:13

I'm trying to build this query, but it's not working:
Using sDac 6.5.9, delphi XE, windows 7
if (SearchString <> '') then
begin
gQuery.SQL.Add('select name,uid');
gQuery.SQL.Add('from cust');
gQuery.SQL.Add('where IsActive =''true'' and name like ''%:sString%''');
gQuery.SQL.Add('order by Name');
gQuery.ParamByName('sString').AsString := SearchString;---error, parameter not found


Is my query bad, or is it the 'like' part of it?

AndreyZ

Re: paramters and like

Post by AndreyZ » Thu 15 Nov 2012 10:05

Hello,

You are using parameters in the wrong way. Your SQL code does not contain the sString parameter, it contains the '%:sString%' constant string. Here is a correct code:

Code: Select all

if (SearchString <> '') then
begin
  gQuery.SQL.Add('select name,uid');
  gQuery.SQL.Add('from cust');
  gQuery.SQL.Add('where IsActive =''true'' and name like :sString');
  gQuery.SQL.Add('order by Name');
  gQuery.ParamByName('sString').AsString := '%' + SearchString + '%';

ccmcbride
Posts: 101
Joined: Tue 01 May 2007 16:36

Re: paramters and like

Post by ccmcbride » Thu 15 Nov 2012 16:37

ty. I think I figured that out at about 2 am thie morning in my sleep,when it came together.

AndreyZ

Re: paramters and like

Post by AndreyZ » Thu 15 Nov 2012 16:49

If any other questions come up, please contact us.

Post Reply