Best way to import csv or excel file in SQL Server 2005 using .net MVC view

I am looking for a better method to import a csv or excel file into SQL Server 2005 using .net MVC.

Thanks.

+5
source share
2 answers

There is a really good library called FileHelpers , which is a) 100% free, b) completely in C #, and it can easily import any text file - separated by commas, separated by tabs, fixed width, etc.

You should not have a problem with this to load the CSV file into objects in memory and save them to SQL Server using ADO.NET.

FileHelpers , , . "" ( , ).

:

FileHelperEngine<Customer> engine = new FileHelperEngine<Customer>();
Customer[] dataLoaded = engine.ReadFile(fileName);

, , ( ), , SQL-:

using(TransactionScope ts = new TransactionScope())
{
   foreach(Customer c in dataLoadad)
   {
      SaveCustomer(c);
   }

   ts.Complete();
}

DataTable SqlBulkCopy SQL Server - !

UPDATE:
[DelimitedRecord] BlackListDevice?

+3

, , FileHelper.

0

All Articles