Values not inserted in SQL Server database
I want to suggest you to extend your if expression one step further as shown below to check whether the session value is greater than 0
as shown below.
if (Convert.ToString(deliverypreference) != "" && Convert.ToString(Session["DeliveryPreference"]) != "" && Convert.ToDecimal(deliverypreference) > 0 && Convert.ToDecimal(Session["DeliveryPreference"]) > 0)
{
//Your insert logic as you have written.
}
As you might be aware sometime when your session variable might not be blank or null string but the value in session is equal to the 0. In that case your code will execute but the data will not inserted properly.
The second workaround I want to suggest you to disable allow null value in SQL Server column by modifying table in design mode.
Hello I promise I will add code to my answer but actually the problem turned out to be restarting of IIS server.