Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
 
 
To
25/06/2010 17:12:05
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01470620
Message ID:
01470632
Views:
35
>>1. Remove RETURN statement from your SP. Stored procedure in T-SQL can only return an integer value (usually error code if non 0)
>
>I tried that, but it didn't make a difference.
>

Right, it will just correct the SP. SP can only return integer value. Anything else is simply ignored.


>>
>>You also need to set up parameter's direction - Output (which I see you're doing). Also, why instead of using SQLParameter you're using IDbDataParameter ?
>>
>
>I do not know what all this means, I am just following an example from the help file for Mere Mortals.
>
>>Also, what does out cmd means?
>>Is there any specific reason for this or this is in TMM examples?
>>
>>Also, this line IDbDataParameter param = (IDbDataParameter)cmd.Parameters["@newNumber"]; is wrong and should not be here.
>>
>>You should get your value using param1 which you declared above. param1 holds the parameter's value. Also, instead of ExecuteScalar you need to use ExecuteNonQuery in your case.
>
>This was copied straight from the help file. Here's the example:
>
>
public void TestOutputParams()
>{
>   // Create the parameter and set the direction
>   IDbDataParameter param1 = this.CreateParameter("@result", 0);
>   param1.Direction = ParameterDirection.Output;
>
>   // Call the stored procedure and pass the parameter
>   IDbCommand cmd;
>   this.ExecSprocScalar("OutputParamTest", out cmd, param1);
>
>   // Retrieve the value from the command object
>   IDbDataParameter param = (IDbDataParameter)cmd.Parameters["@result"];
>   int x = (int)param.Value;
>}
It looks to me as a bug in the Help file (incorrect Help). Search for a better example (and preferably using SQLParameter in the Help). That particular piece of code is wrong - (at least last 2 lines seem wrong to me - you already declared parameter - just get it).

So, if you want to use that particular sample - comment out the extra declaration and use param1 instead of param at the end.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform