I want to get the highest attribute "ID" from my XML file.
My code:
var doc = XElement.Load("invoices.xml");
var q = (from f in doc.Element("ListOfInvoices").Elements("Invoice")
orderby f.Attributes("ID") descending
select f.Attribute("ID")).FirstOrDefault();
When in my XML file is one of Invoice code works, but when is for example 2 invoice I have an error:
At least one object must implement IComparable.
Try casting f.Attributes("ID")
into an int
if it's numeric or a string
if it's alphanumeric like this:
var q = (from f in doc.Element("ListOfInvoices").Elements("Invoice")
orderby (int)f.Attribute("ID") descending
select f.Attribute("ID")).FirstOrDefault();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With