I'm using a service that is used between multiple projects. In this service we do the calls to insert/update sql tables using stored procedures. From the project if a variable is empty or null the application should pass through a db null value and in turn sql should set the default value to 'N'. This, however is throwing an exception that a null value cannot be inserted.
Assigning a value to a paramater:
cmd.Parameters.AddWithValue("@PP_Ref", IIf(String.IsNullOrEmpty(ParkingPermit), DBNull.Value, ParkingPermit))
This is how the variable is set in the sql stored procedure:
ALTER PROCEDURE [dbo].[SP_SaveCustomer]
@PP_Ref char(1) = 'N',
Exception that is received:
{"Cannot insert the value NULL into column 'Cust_PP_Ind', table 'dbo.Customer';
column does not allow nulls. INSERT fails." & vbCrLf & "The statement has been terminated."}
The variable passed will populate 'Cust_PP_Ind' (Cust_PP_Ind = @PP_Ref) in the insert and update statement. How do I set the default value through sql and not through code (and allow null value to be passed from code)?