Publish date: 2003-01-05
SELECT with parameter, Command and RecordSet
function TPxBank.GetInfo(intID: Integer; out strBankName, strLocation: WideString; out intMFO: Integer): HResult;
var
rs: _RecordSet;
cmd : _Command;
begin
Result := S_OK;
rs := CoRecordset.Create;
cmd := CoCommand.Create;
try
cmd.Set_ActiveConnection(GetConnection);
cmd.CommandText := 'select id_bank, bank, location, mfo from banks where id_bank = ?';
cmd.Parameters.Append(cmd.CreateParameter('id_bank', adInteger, adParamInput, -1, intID));
rs.Open(cmd, EmptyParam, adOpenKeyset, adLockOptimistic, adCmdText);
if rs.RecordCount = 1 then begin
strBankName := rs.Fields['BANK'].Value;
strLocation := rs.Fields['LOCATION'].Value;
intMFO := rs.Fields['MFO'].Value;
end;
SetComplete;
except
on E: Exception do begin
Result := E_FAIL;
SetAbort;
raise;
end;
end;
end;
