I trying simple code on 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();
And I got an error:
[ODBC Firebird Driver][Firebird]Dynamic SQL Error SQL error code = -206 Column unknown ID At line 1, column 35.
If I change param name to ? its working fine:
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();
How I can use named parameters with OLE ADO.Commanad ? Whats wrong ?
Tnx
:ParamName
is Delphi's placeholder for named parameters in its SQL wrapper components, like TADOQuery
. It is not ADO's native syntax, ?
is the correct placeholder for parameters when working with ADO's OLE API directly.