Click here to Skip to main content
14,490,316 members
Rate this:
Please Sign up or sign in to vote.
See more:
i am trying to put August 2009 in obj.Completion date and nullreference exception is occurring what am i doing wrong



<clinical_study rank="1"> 
<completion_date type="Actual">August 2009
</completion_date>

</clinical_study>


What I have tried:

XmlNodeList completiondate = xml.SelectNodes("/clinical_study");

                foreach (XmlNode xn in completiondate)
                {
                    if (obj.completion_date == null)
                    {
                        obj.completion_date = xn["completion"].InnerText.ToString();
                    }
                    else {
                        break;
                    }
                }
Posted
Updated 14-Apr-16 2:12am
Comments
ZurdoDev 14-Apr-16 8:06am
   
xn is likely null. Just debug your code and you'll quickly see exactly what is happening.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

obj.completion_date = xn["completion_date"].InnerText.ToString();
   
Comments
Richard Deeming 14-Apr-16 9:37am
   
No need for the .ToString() - InnerText is already a string! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100