procedure TForm1.Button1Click(Sender: TObject);
var x:Integer;
begin
with ADOStoredProc1 do
begin
ProcedureName := 'My_Test';
Parameters.Clear;
Parameters.CreateParameter('Msg', ftstring, pdInput, 20,'test str'); // 用户输入参数
Parameters.CreateParameter('Return', ftInteger, pdOutput, 0, 0); // 存储过程返回参数
Prepared := True;
ExecProc;
x:= Parameters.ParamByName('Return').Value ;
end;
ShowMessage(IntToStr(x));
end;
存储过程
alter PROCEDURE[dbo].[My_Test]
@Msg nvarchar(50),
@Return int output
AS
declare @x int
--declare @re int
select @x=0
IF @x=0
begin
set @Return=11
return 0
end
ELSE
begin
-- ...
set @Return=2
RETURN -1
end