locked
CrmDateTime won't convert to DateTime RRS feed

  • Question

  • Hello,

    I've been trying for litterally hours and I become desperate to find a solution. I've researched for hours on internet too and nothing could help.

    I have a "prospect" entity in the CRM with a CrmDateTime field. Through the web service, I query a "prospect" as one instance of a Lead. I want to put the CrmDateTime in a dateTimePicker control. The intellisense suggested all, so I did not put a field that does not exist in the CRM.

        tbNomEnfant2.Text = currLead.new_enfant2; //This works fine

                dtpNaissanceEnfant1.Value = Convert.ToDateTime(currLead.new_naissanceenfant1.Value);

                DateTime test = Convert.ToDateTime(currLead.new_naissanceenfant1.Value);

    Both of the attempt will return an error. When I debug, currLead.new_naissanceenfant1 indicates Null and the .Value won't return anything. 

    I've tried to 20 different approaches or so. I've tried DateTime.Parse and it won't help. I've tried to intercept by using.

    if (currLead.new_naissanceenfant1.IsNull) {} 

    and this line would also return an error. There is no type mistake

    Do you have any idea of what I'm doing wrong? The field has no value in this case I'm testing, so it may be null, but there has to be a way to intercept.

    Thank you very much!

    Mathieu

    P.s. The Error I get is Object reference not set to an instance of an object. (NullReferenceException)

    EDIT: I've just tried to simplify the whole thing:

    mtbNaissanceEnfant1.Text = currLead.new_naissanceenfant.value 

    So there is no more question of conversion, but it still gives the same answer.

    Wednesday, October 20, 2010 6:05 PM

Answers

  • I think you need to cast as CrmDateTime and then use the value:

    DateTime.Parse(((CrmDateTime)currLead.new_naissanceenfant1).Value);

    Chris

    Wednesday, October 20, 2010 8:56 PM