I have the following stored procedure
CREATE PROCEDURE [dbo].[usp_GetData]
@foo VARCHAR (20), @bar bit = 1
AS ...
This provides the correct result when called in SSMS.
EXEC dbo.usp_GetData @foo = 'Hellow World', @bar = 0
Although when calling within a C# application as per below
cmd.Parameters.Add(new SqlParameter("@foo", foo));
cmd.Parameters.Add(new SqlParameter("@bar", 0));
& is captured by the profiler as below.
exec dbo.usp_GetData @foo=N'Hello World',@bar=default
Does a parameter that overides the default have to be passed differently?
The default is an input parameter. To specify an output parameter, the OUTPUT keyword must be specified in the definition of the parameter in the CREATE PROCEDURE statement. The procedure returns the current value of the output parameter to the calling program when the procedure exits.
As a program, a stored procedure can take parameters. There are three types of parameters: IN, OUT and INOUT.
Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure. In the Execute Procedure dialog box, specify a value for each parameter and whether it should pass a null value.
You can also pass parameters to a stored procedure, so that the stored procedure can act based on the parameter value(s) that is passed.
Use
cmd.Parameters.AddWithValue("@bar", 0)
This way you know you actually passing the value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With