Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I save Object back to the database with a null value for a date parameter?
    text
    copied!<p>I have a date picker on my WPF window that is optional. By that I mean there is no requirement to select a date before saving the Employee object back to the database. However I am having trouble getting the save to work when try to save it without the date set. The error is:</p> <p><em><strong>SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.</em></strong></p> <p>What am I doing wrong? </p> <pre><code>private DateTime _ExpectedPromotionDate; public DateTime ExpectedPromotionDate { get { return _ExpectedPromotionDate; } set { DateTime temp; if (DateTime.TryParse(Convert.ToString(_ExpectedPromotionDate), out temp)) { _ExpectedPromotionDate = value; } else { _ExpectedPromotionDate = DBNull.Value; //throw new ApplicationException("Promotion Date is mandatory."); } } } </code></pre> <p>By the way my save function looks like this</p> <pre><code>public bool Save() { try { Dac.ExecuteNonQuery("Manpower_InsertEmployee", Dac.Parameter(CN_LoginId, LoginId), Dac.Parameter(CN_StoreId, StoreId), Dac.Parameter(CN_FirstName, FirstName), Dac.Parameter(CN_LastName, LastName), Dac.Parameter(CN_EeRole, EeRole), Dac.Parameter(CN_RoleRank, RoleRank), Dac.Parameter(CN_IsUpNComing, IsUpNComing), Dac.Parameter(CN_ExpectedPromoDate, ExpectedPromotionDate), Dac.Parameter(CN_IsPotentialManager, IsPotentialManager)); return true; } catch { //throw new Exception (String.Format("{0} {1}", ex.Message, ex.StackTrace)); throw new Exception("There was an error during the save process."); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload