TFDQuery.Prepare cannot determine parameter types for INSERT query on MS SQL SERVER

不打扰是莪最后的温柔 提交于 2019-11-29 12:29:07

I would follow help here and avoid calling Prepare before parameters are defined (their data types are fully specified). You haven't missed anything but this note from help:

It is recommended to setup parameters before the Prepare call.

For common ODBC drivers (you are still talking to an ODBC driver, no matter if they internally uses OLE DB to communicate with the DBMS), FireDAC doesn't determine parameter data types for the prepared command. Instead, it prepares command statement on the target DBMS and tries to bind existing ones from the Params collection. That's how the Prepare method is implemented (Tokyo).

ODBC API provides the SQLDescribeParam function to obtain parameter details for the prepared command, but FireDAC doesn't use it anywhere (at this time). Instead, it leaves building parameter collection manually. Which is not wrong, because in the end, it is the developer who needs to know which value to assign to a certain command parameter so as to know this value type.

Set each of your parameters DataType property, and then you can call Prepare ie:

  qry.ParamByName('foo').DataType := TFieldType.ftString;
  qry.ParamByName('bar').DataType := TFieldType.ftInteger;
  qry.Prepare;

The DataType property is of type Data.DB.TFieldType, here is a list of all possible values

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