I am trying to read a CSV file with CsvHelper, load each record into a DataTable, and then use SqlBulkCopy to insert the data into a database table. With the current code, I get
I was able to get this to work by adding a DataTable row and filling it in explicitly, instead of trying to add a CsvHelper record as a row.
I used the following part instead of the similar part that is shown above:
foreach (var record in records)
{
DataRow row = dt.NewRow();
record.CompanyId = company.Id;
row["Date"] = record.Date;
row["Close"] = record.Close;
row["AdjClose"] = record.AdjClose;
row["High"] = record.High;
row["Low"] = record.Low;
row["Open"] = record.Open;
row["Volume"] = record.Volume;
row["CompanyId"] = record.CompanyId;
dt.Rows.Add(row);
}
If you can solve the issue without so much hard coding, I will accept your answer as the answer.