entity csv insert DB

  • 48
  • 0
  • 2017-09-15

EF

https://stackoverflow.com/questions/38096284/i-want-to-import-data-from-csv-file-to-sql-database-using-entity-framework 

var readcsv = File.ReadAllText(filepath);
//var readcsv = File.ReadAllText(filepath, Encoding.GetEncoding(950)); big5用這個
string[] csvfilerecord = readcsv.Split('\n');

foreach (var row in csvfilerecord)
{
  if (!string.IsNullOrEmpty(row))
  {
    var cells = row.Split(',');
    var card = new Cards
      {
         number = cells[0], // number is in first cell
         cvv = cells[1],   // cvv is in second cell
         // ...
      };
  }
}