0

I am reading CSV files using LumenWorks.CsvReader. It works fine when I do not try to prescribe a Decimal type column like this:

cols = new List<Column>  {
     new Column { Name="client", Type=typeof(string) },
     new Column { Name="gross_sell", Type=typeof(Decimal) }
}

... and reading into a DataTable like this:

DataTable dt = new DataTable();
using (StreamReader stream = new StreamReader(csvFileName, encoding))
using (CsvReader reader = new CsvReader(stream, hasHeaders, delimiter))
{
    reader.Columns = cols;
    dt.Load(reader);
}

The problem is that it fails on values like 42.53 telling me that the input string has bad format. The default culture info says it should be 42,53.

How can I tell to LumenWorks.CsvReader that it should use invariant culture in the case?

pepr
  • 20,112
  • 15
  • 76
  • 139
  • I haven't used that library in order to read files but I guess you could perform a `Decimal.TryParse` manually providing the desired culture. Anyway, I use to choose FileHelpers for reading/writing. Give it a try, works like a charm. – Gonzo345 Dec 18 '18 at 09:45
  • @Gonzo345 Well, I know more ways how to parse string to Decimal. What I need to know is how can I pass the information to the `LumenWorks.CsvReader`. – pepr Dec 18 '18 at 10:40

0 Answers0