forum

Home / DeveloperSection / Forums / Handle null exception in linq to xml query

Handle null exception in linq to xml query

Anonymous User 2449 14-Aug-2014

var qXML = (from nm in xelement.Descendants("EmployeeFinance")

            where nm.Element("Status").Value.Contains(status) && int.Parse(nm.Element("Empersonal_Id").Value) == ele.EmpId

            select nm).SingleOrDefault();

Above is my sample code. Now there are instances where ele.EmpId will be present in the xml and instance where it will not be. How do i handle the null exception that is thrown when ele.EmpId is not found.


c# c# 
Updated on 14-Aug-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By