Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

LINQ to XML Getting records from StartDate to EndDate

$
0
0
I am using linq to XML in C#

I have an XML where records are stored

<ID>1</ID>
<Date>01/12/2012 </Date>
<value>10</value>

<ID>2</ID>
<Date>02/12/2012 </Date>
<value>10</value>

<ID>3</ID>
<Date>03/12/2012 </Date>
<value>10</value>

I am trying to get the records for selected FromDate to ToDate.
for example between fromDate > 01/12/2012 & endDate < 03/12/2012

so I am writing the query as

 var r = from pro in d.Descendants("products")
                        where
                            (DateTime)pro.Element("Date") < Convert.ToDateTime(dateTimePickerToDate.Text) && (DateTime)pro.Element("Date") > Convert.ToDateTime(dateTimePickerFromDate.Text)                        
                        select pro;
             
                foreach (var p in r)
                {
                    currentproductID = p.Element("ID").Value;                   
                }

but it is giving an error "string not recognized as a valid datetime"

Any idea why I am getting an error?

Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>