Note that there are some explanatory texts on larger screens.

plurals
  1. POString was not recognized as a valid DateTime - Whats wrong?
    text
    copied!<p>I have been getting an annoying littler error and cannot for the life of me figure out why it is being cause. I have an xml file where i am storing data, as shown below.</p> <pre><code>- &lt;EmployeeFinance&gt; &lt;EmployeeEmploy_Id&gt;5584&lt;/EmployeeEmploy_Id&gt; &lt;EmpPersonal_Id&gt;30358&lt;/EmpPersonal_Id&gt; &lt;No_DaysWorked&gt;30&lt;/No_DaysWorked&gt; &lt;Date_Appointment&gt;17/02/2012&lt;/Date_Appointment&gt; &lt;Date_Employment&gt;02/05/1984&lt;/Date_Employment&gt; &lt;Date_Termination&gt;01/01/0001&lt;/Date_Termination&gt; &lt;Payperiod_StartDate&gt;01/01/2013&lt;/Payperiod_StartDate&gt; &lt;Payperiod_EndDate&gt;31/01/2013&lt;/Payperiod_EndDate&gt; &lt;BatchNumber&gt;38&lt;/BatchNumber&gt; &lt;PAYE_ToDate_Computed&gt;0&lt;/PAYE_ToDate_Computed&gt; &lt;Income_Tax_RateID&gt;0&lt;/Income_Tax_RateID&gt; &lt;NIS_RateID&gt;0&lt;/NIS_RateID&gt; &lt;NIS_weeks_worked&gt;0&lt;/NIS_weeks_worked&gt; &lt;/EmployeeFinance&gt; </code></pre> <p>If you look at the date nodes, Payperiod_StartDate,Payperiod_EndDate, Date_Appointment etc. They all have the same format. Now in my C# code, when i write my query to select from the xml file i get the <strong>String was not recognized as a valid DateTime</strong> error. WHen i comment out all the other dates and leave start_date, it works. They are the same format , i cant see what i am doing wrong. Please help me.</p> <pre><code> var context = new SSPModel.sspEntities(); XElement xelement = XElement.Load(GlobalClass.GlobalUrl); XDocument doc = XDocument.Load(GlobalClass.GlobalUrl); var query = from nm in xelement.Elements("EmployeeFinance") select new EmployeeEmploy { Employee_Personal_InfoEmp_id = (int)nm.Element("EmpPersonal_Id"), Substantive_designation = (int)nm.Element("Position_Id"), Grade_Id = (int)nm.Element("Grade_Id"), PositionTotal_PtBasic = (double)nm.Element("Sum_AllPosition"),//part of basic GradeTotal_PtBasic = (double)nm.Element("Sum_AllGrade"), //part of basic Housing_Allowance = (double)nm.Element("Housing"), Base_Pay = (double)nm.Element("Base_Pay"), startDate = (DateTime)nm.Element("Payperiod_StartDate"), endDate = (DateTime)nm.Element("Payperiod_EndDate"), Date_of_Appointment = (DateTime)nm.Element("Date_Appointment"), Date_of_Employment = (DateTime)nm.Element("Date_Employment"), Termination_date_actual = (DateTime)nm.Element("Date_Termination"), Base_Pay_Currency = (string)nm.Element("Currency"), Exchange_rate = (double)nm.Element("Exchange_Rate") }; var x = query.ToList(); foreach (var xy in x) { Debug.WriteLine(xy.endDate); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload