How can I retrieve the return value of a stored procedure using iBatis.NET? The below code successfully calls the stored procedure, but the QueryForObject<int> call returns 0.
SqlMap
<procedure id="MyProc" parameterMap="MyProcParameters" resultClass="int">
MyProc
</procedure>
<parameterMap id="MyProcParameters">
<parameter property="num"/>
</parameterMap>
C# code
public int RunMyProc( string num )
{
return QueryForObject < int > ( "MyProc", new Hashtable { { "num", num } } );
}
Stored Procedure
create procedure MyProc
@num nvarchar(512)
as
begin
return convert(int, @num)
end
FYI, I'm using iBatis 1.6.1.0, .NET 3.5, and SQL Server 2008.
It's not pretty, but this works:
SqlMap
<statement id="MyProc" parameterClass="string" resultClass="int">
declare @num int
exec @num = MyProc #value#
select @num
</statement>
C# code
public int RunMyProc( string num )
{
return QueryForObject < int > ( "MyProc", num );
}