我在Delphi上尝试了简单的代码:
Connection := CreateOleObject('ADODB.Connection');
Connection.ConnectionString := 'dsn=rollcontrol_im';
Connection.Open;
Command := CreateOleObject('ADODB.Command');
Command.CommandText := 'SELECT * FROM log where log.id = :id';
Command.ActiveConnection := Connection;
Command.Parameters.Append( Command.CreateParameter('id', adInteger, adParamInput, 4 {size}, 5 {value}) );
RecordSet := Command.Execute();我犯了个错误:
ODBC SQL Error SQL错误代码= -206列未知ID,位于第1行第35列。
如果我改名为?其工作情况如下:
Connection := CreateOleObject('ADODB.Connection');
Connection.ConnectionString := 'dsn=rollcontrol_im';
Connection.Open;
Command := CreateOleObject('ADODB.Command');
Command.CommandText := 'SELECT * FROM log where log.id = ?';
Command.ActiveConnection := Connection;
Command.Parameters.Append( Command.CreateParameter('?', adInteger, adParamInput, 4 {size}, 5 {value}) );
RecordSet := Command.Execute();如何在OLE ADO.Commanad中使用命名参数?出什么事了?
Tnx
发布于 2021-06-21 14:54:46
:ParamName是Delphi组件中命名参数的占位符,如TADOQuery。它不是ADO的本机语法,当直接使用ADO的OLE API时,?是正确的参数占位符。
https://stackoverflow.com/questions/68066795
复制相似问题