Board index » delphi » Problems running parametrized query with LIKE operator against SQL server nvarchar datatype

Problems running parametrized query with LIKE operator against SQL server nvarchar datatype

After applying the ADOExpress update pack, due to the MDAC2.6 BOF/EOF error,
i ran into the following problem :

Running a query using the like operator in combination with parameters
against SQL server nvarchar datatypes returns empty resultsets. Compiling
the same code with the original Delphi version works fine as does changing
the datatype to varchar.

procedure DoesNotWork(SearchString : string);
begin
     WSet.SQL.Add('select * from customers where name like :p0');
     WSet.Parameters[0].Value:='%'+SearchString+'%';
     WSet.Open; {No results here}
end;

procedure WorksFine(SearchString : string);
begin
     WSet.SQL.Add('select * from customers where name like "%A%"');
     WSet.Open; {Works just fine}
end;

Seems to be a bug but where do i report this at Borland?

Regards,

Frank

 

Re:Problems running parametrized query with LIKE operator against SQL server nvarchar datatype


Quote
"Frank Zimmermann" <Fra...@zimec.nl> wrote in message

news:3b1b85bd_1@dnews...

Quote
> After applying the ADOExpress update pack, due to the MDAC2.6 BOF/EOF
error,
> i ran into the following problem :

> Running a query using the like operator in combination with parameters
> against SQL server nvarchar datatypes returns empty resultsets. Compiling
> the same code with the original Delphi version works fine as does changing
> the datatype to varchar.

> procedure DoesNotWork(SearchString : string);
> begin
>      WSet.SQL.Add('select * from customers where name like :p0');
>      WSet.Parameters[0].Value:='%'+SearchString+'%';
>      WSet.Open; {No results here}
> end;

Hi,

Bug or not I don't know, but will this work ?

procedure DoesNotWork(SearchString : string);
begin
     WSet.SQL.Add('select * from customers where name like :p0');
     WSet.Parameters[0].Value := #39 + '%'+SearchString+'%' + #39;
     WSet.Open; {No results here}
end;

hth,
Leo

Other Threads