How to do Column Mapping for a CSV file while uploading using c#

1.2k views Asked by At

Can we do column mapping while uploading a CSV File.

I have a system, which will upload CSV files and store the data into SQL Server tables. But some records of the tables are wrong.

The records are wrong because, the data is split into 2 or more lines, but all the lines will have the same amount of commas, just as same as the number of commas we have for heading. So this cause wrong data to enter in columns.

So if I can map the columns while uploading the CSV and if it can show me the lines which have errors, it could possibly solve this issue.

Can anyone help plz?

1

There are 1 answers

0
jshedley On

For CSV parsing I tend to use the Jet engine, it is great for parsing CSV files.

There is a great example here: http://www.codeproject.com/Articles/27802/Using-OleDb-to-Import-Text-Files-tab-CSV-custom

Thanks Jamie