Link to home
Start Free TrialLog in
Avatar of Marius0188
Marius0188

asked on

Delphi 7 :: Executing MS SQL 2005 Stored Procedure with Output Variabel

Dear Experts,

I can't find a working example of how to execute a MS SQL 2005 stored procedure which returns an output variable within Delphi 7 code.

Please show me an example.

Thanks.
Avatar of Marius0188
Marius0188

ASKER

Please see my Delphi code below, when running this code I receive the following Delphi runtime error message: see attached image...
var
  sResult :String;
begin
  ADOStoredProc1.ProcedureName := 'spGetTritonPartTypes';
  ADOStoredProc1.Parameters.Refresh;
  ADOStoredProc1.Parameters.ParamValues['@po']  := '5000';
  ADOStoredProc1.ExecProc;
  sResult := ADOStoredProc1.Parameters.ParamValues['@output'];
 
  ShowMessage(sResult);
end;

Open in new window

sp-error.jpg
Avatar of TheRealLoki
use a TADOQuery and do it like this

ADOQuery1.SQL.Text :=  'set nocount on' + #13#10 +
                                          'declare @res int ' + #13#10 +
                                          'exec @spGetTritonPartTypes :po, @output OUTPUT ' + #13#10
                                          'set nocount off ' + #13#10 +
                                          'select @res as res';

with adoquery1.parameters.parambyname('po') do
begin
  paramtype := ftInteger;
  value := 5000;
end;
AdoQuery1.Open;
ShowMessage(ADOQuery1.FieldByName('res').AsInteger);

something like that anyway, I'm not near my dev p.c.
ASKER CERTIFIED SOLUTION
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the reply.
Just 1 fix and it is working 100%.

 "@spGetTritonPartTypes"
 shoud be: "spGetTritonPartTypes"

Thanks again.