How to read a CSV file into a .NET Datatable

后端 未结 22 2571
野性不改
野性不改 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 05:50

    With Cinchoo ETL - an open source library, you can easily convert CSV file to DataTable with few lines of code.

    using (var p = new ChoCSVReader(** YOUR CSV FILE **)
         .WithFirstLineHeader()
        )
    {
        var dt = p.AsDataTable();
    }
    

    For more information, please visit codeproject article.

    Hope it helps.

提交回复
热议问题