How to create a command passing parameters

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
brace
Posts: 227
Joined: Wed 14 Feb 2007 08:26

How to create a command passing parameters

Post by brace » Thu 26 Oct 2017 12:30

I would like to use TMSQuery to create a parametric command.

I usually do
MSQuery1.SQL.Text := 'CREATE DATABASE ' + aMyDBName;

but if I have
CREATE DATABASE :MyDBName
and i try to do
MSQuery1.ParamByName('MyDBName').asstring := aMyDBName;
when i execute the query i have
"Wrong syntax near @P1"

how to avoid this error and use ParamByName succesfully in my context?

Thanks

Stellar
Devart Team
Posts: 496
Joined: Tue 03 Oct 2017 11:00

Re: How to create a command passing parameters

Post by Stellar » Fri 27 Oct 2017 07:45

You cannot pass the database name as a parameter in this query, since this functionality is not supported by MS SQL Server and we cannot affect it. To solve this task, you can use macros. More details about macros here: https://www.devart.com/sdac/docs/index. ... macros.htm

brace
Posts: 227
Joined: Wed 14 Feb 2007 08:26

Re: How to create a command passing parameters

Post by brace » Fri 27 Oct 2017 10:20

Thanks for the reply, now i got the difference between parameter and macro.

Post Reply