A
A
Anton2019-06-17 14:57:18
ASP.NET
Anton, 2019-06-17 14:57:18

Why doesn't CSVHelper read fields from file?

I'm having a problem, csvhelper doesn't see any of the fields in my .csv file (there are many)
5d077ee8df616839537842.png

static OFSStoresDB ReadFile(string filename)
        {
            OFSStoresDB db = new OFSStoresDB();
            StreamReader reader = new StreamReader(filename);
            CsvReader csv = new CsvReader(reader);
            csv.Read();
            csv.ReadHeader();
            csv.Configuration.HasHeaderRecord = true;
            csv.Configuration.BadDataFound = null;
            // Log missing field.
            csv.Configuration.MissingFieldFound = (headerNames, index, context) =>
            {
                Console.WriteLine($"Field with names ['{string.Join("', '", headerNames)}'] at index '{index}' was not found. ");
            };
            while (csv.Read())
                {
                    #region Read raw data

                    var timestampConverter = new TimestampConverter();

                    DateTime reportExtractedAt = csv.GetField<DateTime>("Report_Extracted_At", timestampConverter);

                    // Source Store
                    string srcStoreId = csv.GetField("Src_Store_Id");
                    string srcStoreName = csv.GetField("Src_Store_Name");
....
And already at the first reading of the first field, an error occurs
System.ArgumentNullException: 'Value cannot be null. Parameter name: value'

And in the console writes
Field with names ['Report_Extracted_At'] at index '0' was not found.

What could be the problem, please advise.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
#
#, 2019-06-17
@anton_mra

(on a comment to the question) ... or with a separator "by default" ("," or ";". in the Russian locale it's just ";") .. dig in the direction of setting the locale for the length of the sieswi-reader. a simple example here https://progtask.ru/csv-c-sharp/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question