SQL Server Stored Procedure: how to retrieve both return code and resultset

Posts   
 
    
acl
User
Posts: 94
Joined: 28-Mar-2012
# Posted on: 09-Nov-2022 14:07:11   

Hi,

I'm using the LLBLGen Runtime Version 5.9.2 using the adapter template. I have the following stored procedure:

CREATE PROCEDURE proc
AS
   -- do something…
   SELECT col1
    FROM #temptable;

   RETURN @iRc;
GO

With the generated code I can do the following to fetch the resultset into a typed view:

var result = new TypedViewClasses.RS_ProcTypedView();
adapter.FetchTypedView(result, RetrievalProcedures.GetQueryRS_ProcTypedView(parameter, adapter));

How can retrieve the return code of the stored procedure (the RETURN @iRc)?

Thanks,

andreas

Walaa avatar
Walaa
Support Team
Posts: 14986
Joined: 21-Aug-2005
# Posted on: 09-Nov-2022 21:20:36   

A RetrievalQuery has a Parameters property which contains all parameters used in the DbCommand. You can obtain the value from there. Be aware that the output parameters are often filled after the resultset has been consumed. So if you try to read output parameters before the resultset has been consumed they'll appear empty.

(The Return value is usually parameter 0)

acl
User
Posts: 94
Joined: 28-Mar-2012
# Posted on: 11-Nov-2022 11:16:05   

Thanks Walaa, that worked.