Use DBNull.Value
, instead of null
when passing null values to database.
From Sybase: "You can assign a default value for the parameter in the create procedure statement. This value, which can be any constant, is used as the argument to the procedure if the user does not supply one.".
The following script declares a SP with a default value, and then executes it passing: 2, NULL, DEFAULT, and without any value. You can see that the behavior of not specifying the parameter is the same as passing DEFAULT and it can be different from passing NULL.
That is the distinction I pointed, because when you don't declare the parameter for the Command object that's the type of behavior you get:
CREATE PROCEDURE MySp(@p1 INT = 1)
AS BEGIN
SELECT @p1 AS [parameter_value];
END
GO
EXEC MySp 2; -- parameter value = 2
EXEC MySp NULL; -- parameter value = NULL
EXEC MySp DEFAULT; -- parameter value = 1
EXEC MySp; -- parameter value = 1
GO