参数FDquery delphi不起作用 [英] parameters FDquery delphi does not work

查看:745
本文介绍了参数FDquery delphi不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下delphi代码:

i have the following delphi code:

FDQuery1.SQL.Clear;
FDQuery1.SQL.Add('SELECT * FROM :Tablename');
FDQuery1.ParamByName('Tablename').AsString := 'tasks';
ShowMessage(FDQuery1.sql.Text);
FDQuery1.Open;

(从此链接复制: http://www.delphigroups.info/2 /da/237634.html )

它不起作用,因为参数未填充但保持不变. 有人知道为什么它没有填充吗?

it does not work because the parameter is not filled but stays the same. does somebody know why it is not filled?

推荐答案

因为通常不能在SQL命令中使用参数来替换表名.不过,您在这里很幸运,FireDAC支持预处理程序宏以参数化SQL命令中的表名.因此,您可以编写此示例(请注意,如果要像在代码中一样查看命令,则该命令必须在宏预处理之后进行,例如,在调用

Because you cannot use parameters for table name substitution in SQL commands in general. You are lucky enough here though, FireDAC supports preprocessor macros to parametrize table names in SQL commands. So you can write for example this (note that if you want to see the command as you did in your code, it must be after macro preprocessing, that is e.g. after calling Prepare):

FDQuery1.SQL.Text := 'SELECT * FROM &TableName';
FDQuery1.MacroByName('TableName').AsIdentifier := 'tasks';
FDQuery1.Open;

有关此类宏的详细信息,请参见 替代变量 主题.

For details about this kind of macros, see the substitution variables topic.

这篇关于参数FDquery delphi不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆