parameters FDquery delphi does not work

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

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; 

(coppied from this link: 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?

回答1:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!