CRM 2011 - Update a Date field in C# to NULL fails RRS feed

  • Question

  • I'm trying to update a date field that has an existing value of 1/1/1900 to a NULL, as this is the MIN date value coming from SQL Server.  However, when I try to update it as NULL, the field is never updated.  Is there some trick in CRM where you cannot set a date field to NULL if it already has a value? 

    There is nothing special with my code.  I am basically doing the following

      crm.Attributes["currentmilestoneestcompl"] = empower.CurrentMilestoneEstCompl;

    The milestone date is a SQL nullable date datatype and can be a date or a NULL.  When it is a date, the update works fine.  But when it is NULL, CRM ignores the update and an existing date in CRM is not set back to NULL.   Is there a trick to this or should this be working? 

    Best regards,


    Jon Rothlander

    • Edited by jrothlander Thursday, July 17, 2014 10:56 AM
    Thursday, July 17, 2014 10:54 AM

All replies

  • CurrentMilestoneEstCompl can be null or DBNull? I think this can be the issue here.

    To clean a CRM date field you need to set it to null, so in your case will be:

    crm.Attributes["currentmilestoneestcompl"] = null;
    check the exact value returned by your CurrentMilestoneEstCompl property

    My blog: www.crmanswers.net - Rockstar 365 Profile

    Thursday, July 17, 2014 11:31 AM
  • Thanks for the feedback. 

    The value of the property is null when it updates.  But that null value is not updated in CRM.  I have even hardcoded a test (below) exactly like yours and it does not work.  It seems that CRM is blocking it and will not update it as a NULL.  Maybe CRM is ignoring it because the attribute is NULL?

    crm.Attributes["dhi_currentmilestoneestcompl"] = null;

    Jon Rothlander

    Thursday, July 17, 2014 2:57 PM
  • try:-




    Regards Faisal

    Thursday, July 17, 2014 2:59 PM
  • I realise this is a bit old now however I've always found that, using a .NET nullable datetime works fine in plugins atleast....

    crm.Attributes["dhi_currentmilestoneestcompl"] = (DateTime?)null;

    • Proposed as answer by fire.storm Friday, November 7, 2014 6:16 PM
    Friday, November 7, 2014 6:16 PM