How to read a CSV file into a .NET Datatable

后端 未结 22 2608
野性不改
野性不改 2020-11-22 05:12

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?

22条回答
  •  青春惊慌失措
    2020-11-22 06:12

    The best option I have found, and it resolves issues where you may have different versions of Office installed, and also 32/64-bit issues like Chuck Bevitt mentioned, is FileHelpers.

    It can be added to your project references using NuGet and it provides a one-liner solution:

    CommonEngine.CsvToDataTable(path, "ImportRecord", ',', true);
    

提交回复
热议问题