How to Get Output Parameters

4 posts, 0 answers
  1. Michael Luna
    Michael Luna avatar
    9 posts
    Member since:
    May 2007

    Posted 28 Sep 2009 Link to this post

    In the following code, the last two parameters, forwarder code and password, are marked as OUTPUT in the stored procedure.  Also, the sproc returns a -1 or a 0 depending on success.  Yet, if I look at the "res" variable right before it is returned, its "OutParameter" property is NULL.  So how can I get at the output parameters and the return val?

            public static IQueryResult RetrieveAttributes(IObjectScope scope, string edireceiveretrieveattributesspUserName, string edireceiveretrieveattributesspforwardercode, string edireceiveretrieveattributesspPassword) 
            { 
                IQuery query = scope.GetSqlQuery("edi_receive_retrieve_attributes_sp ?,?,?"null"VARCHAR edi_receive_retrieve_attributes_sp_UserName,VARCHAR edi_receive_retrieve_attributes_sp_forwarder_code,VARCHAR edi_receive_retrieve_attributes_sp_Password"); 
     
                IQueryResult res = query.Execute(new object[] { edireceiveretrieveattributesspUserName, edireceiveretrieveattributesspforwardercode, edireceiveretrieveattributesspPassword }); 
                int a = res.Count;//Actually executes the query 
     
                return res; 
            } 
     

  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 30 Sep 2009 Link to this post

    Hello Michael Luna,

    As I have written in a similar thread of yours, you will need to explicitly mark the properties that are output parameters with the OUT in front of each type. After that you will need to retrieve the proper values from the OutParameter collection using the parameter name as key. Here is an example that marks the last property from your method as an output one.
    public static IQueryResult RetrieveAttributes(IObjectScope scope, string edireceiveretrieveattributesspUserName, string edireceiveretrieveattributesspforwardercode,out string edireceiveretrieveattributesspPassword)  
            {  
                IQuery query = scope.GetSqlQuery("edi_receive_retrieve_attributes_sp ?,?,?"null"VARCHAR edi_receive_retrieve_attributes_sp_UserName,VARCHAR edi_receive_retrieve_attributes_sp_forwarder_code,OUT.VARCHAR edi_receive_retrieve_attributes_sp_Password");  
      
                IQueryResult res = query.Execute(new object[] { edireceiveretrieveattributesspUserName, edireceiveretrieveattributesspforwardercode, edireceiveretrieveattributesspPassword });  
                int a = res.Count;//Actually executes the query  
                edireceiveretrieveattributesspPassword = (string)res.OutParameter["edi_receive_retrieve_attributes_sp_Password"]; 
                return res;  
            }  
    Please feel free to contact us if any difficulties arise.

    Sincerely yours,
    Petar
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Michael Kellogg
    Michael Kellogg avatar
    8 posts
    Member since:
    Oct 2009

    Posted 01 Oct 2009 Link to this post

    Petar, is there a way to get at the return value of the stored proc?

    Example, the last line of my sproc says:

    RETURN @@ROWCOUNT

    How can I get at that?  It is not attached to a parameter and it doesn't seem to be in the OutParam array anywhere.
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 02 Oct 2009 Link to this post

    Hi Michael Kellogg,

    Unfortunately this is not currently supported by Telerik OpenAccess ORM. A possible workaround is to expose the result as an Out parameter and use the approach described above.

    All the best,
    Damyan Bogoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top