How can I load a CSV file into a System.Data.DataTable, creating the datatable based on the CSV file?
Does the regular ADO.net functionality allow this?
private static DataTable LoadCsvData(string refPath)
{
var cfg = new Configuration() { Delimiter = ",", HasHeaderRecord = true };
var result = new DataTable();
using (var sr = new StreamReader(refPath, Encoding.UTF8, false, 16384 * 2))
{
using (var rdr = new CsvReader(sr, cfg))
using (var dataRdr = new CsvDataReader(rdr))
{
result.Load(dataRdr);
}
}
return result;
}
using: https://joshclose.github.io/CsvHelper/