Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to put August 2009 in obj.Completion date and nullreference exception is occurring what am i doing wrong



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

</clinical_study>


What I have tried:

C#
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

C#
obj.completion_date = xn["completion_date"].InnerText.ToString();
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900