It would seem I need help getting to the bottom of what should be a simple problem. I am updating some existing code and I have a stored procedure that has nullable paramters and updates a table.
Example SP Parameters
,@Paid bit = NULL
,@Despatched bit = NULL
SP Code Example
,Paid = ISNULL(@Paid, Paid)
,Despatched = ISNULL(@Despatched, Despatched)
,MarkedAsPaid = ISNULL(@MarkedAsPaid, MarkedAsPaid)
,MarkedAsDespatched = ISNULL(@MarkedAsDespatched, MarkedAsDespatched)
C# Code
cmd.Parameters.Add(new SqlParameter("@Despatched", 0));
cmd.Parameters.Add(new SqlParameter("@Paid", 0));
if (request.ShippedDate != null && request.ShippedDate != DateTime.MinValue.ToString())
{
cmd.Parameters["@Despatched"].Value = 1;
}
if (request.PaymentMethod == "PayPal" && request.CheckOutStatus == "NoPaymentFailure")
{
cmd.Parameters["@Paid"].Value = 1;
}
When I run this code and the above if conditions are not met the field values remain as is (NULL
) if they are met the field is updated to 1
. Any idea why they are not being updated to 0 when the conditions are not met?