I am parsing CSV files and creating a list of objects that i will need to import them in a SQL DB. The csv file has different header names that i can map them for each column of a specific table.
LINQ fails as the names do not match.
I did try every possible tutorial and side way but cannot map the csv headers to a specific column of the db.
using (TextReader reader = File.OpenText(file))
{
List<CSVObject> ListCSVObject = new List<CSVObject>();
CsvReader csv = new CsvReader(reader);
csv.Configuration.Delimiter = ",";
csv.Configuration.MissingFieldFound = null;
while (csv.Read())
{
CSVObject objectRow = csv.GetRecord<CSVObject>();
double time = Convert.ToDouble(objectRow.Timestamp);
DateTime dateTimeUTC = ConvertFromUnixTimestamp(time);
objectRow.DateTimeUTC = dateTimeUTC;
ListCSVObject.Add(objectRow);
}
LINQToSQLDataContext db = new LINQToSQLDataContext(connectString);
foreach(CSVObject obj in ListCSVObject)
{
db.dbtoinsert.InsertOnSubmit(obj);
}
db.SubmitChanges();
}