Quantcast
Channel: Web Forms
Viewing all articles
Browse latest Browse all 23244

Input string is not in the correct format in Linq to XML

$
0
0

I have a linq/xml statement that I'm splitting of of a tab. If the column is empty in the excel file, then I get an Input string is not in the correct format. Is there a way to get around this? I tried checking for string.empty in my XElement, but that's not working:

var xmlFile = new XElement("Package",
               from str in mainList
               let fields = str.Split('\t')
               select new XElement("Record",
                                       new XElement("recordId", FileId),
                                       new XElement("LineId", (lineId++).ToString()),

                                       new XElement("amount", (fields[21].Trim() == string.Empty ? Decimal.Parse("0.00").ToString() :
                                                                   Decimal.Parse(fields[21].Replace("\"", string.Empty).Trim(), NumberStyles.Currency).ToString()))

                                  )
                              );


Viewing all articles
Browse latest Browse all 23244

Trending Articles



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