This is a migrated thread and some comments may be shown as answers.

How to Get Output Parameters

3 Answers 40 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Michael Luna
Top achievements
Rank 1
Michael Luna asked on 28 Sep 2009, 09:34 PM
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; 
        } 
 

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 30 Sep 2009, 05:17 PM
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.
0
Michael Kellogg
Top achievements
Rank 1
answered on 01 Oct 2009, 11:39 PM
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.
0
Damyan Bogoev
Telerik team
answered on 02 Oct 2009, 04:22 PM
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.
Tags
Getting Started
Asked by
Michael Luna
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Michael Kellogg
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Share this question
or