Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a Stored Procedure with Output Parameter
Message
 
 
To
27/06/2010 11:16:06
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01470620
Message ID:
01470719
Views:
33
>Hey Tim,
>
>I've always used the ParameterDirection.InputOutput rather than just .Output and sure enough, that's what the problem is. If you look at a trace in SQL Profiler to see what actually gets passed to SQL, you'll see that that the parameter is defined as nvarchar(1) when using just the .Output direction (consequently it's truncated), but correctly set to nvarchar(10) when using .InputOutput.
>
>The culprit is actually the .AddWithValue() in combination with using the .Output direction I think. If you use the older methodology for setting the parameter, it will work with the .Output direction:
>
>
>cmd.Parameters.Add("@NextNumber", SqlDbType.VarChar, 10);
>cmd.Parameters["@NextNumber"].Direction = ParameterDirection.Output;
>
>
>I like to use .AddWithValue(), but this little gotcha is something to keep in mind ... always use ParameterDirection.InputOutput instead of ParameterDirection.Output and you will be ok.
>
>I don't know if you were using this, but Sql Profiler is a handy little tool ... it really helps troubleshoot.
>
>~~Bonnie
>
>
I agree - I was also going to suggest to use Add method for the Output parameter instead of AddWithValue. Besides, the sample also used Add method.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform