c# reading csv file gives not a valid path

前端 未结 7 1904
Happy的楠姐
Happy的楠姐 2020-12-05 07:04

I can\'t seem to read a .csv file using the following connection string:

var fileName = string.Format(\"{0}{1}\", AppDomain.CurrentDomain.BaseDirectory, \"Up         


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 07:46

    I recommend you use a CSV parser rather than using the OLEDB data provider.

    Search and you'll find many (free) candidates. Here are a few that worked for me:

    A portable and efficient generic parser for flat files (easiest to use, IMO)
    A Fast CSV Reader (easy to use, great for large data sets)
    FileHelpers library (flexible, includes code generators, bit of a learning curve)

    Typically these will allow you to specify properties of your CSV (delimiter, header, text qualifier, etc.) and with a method call your CSV is dumped to a data structure of some sort, such as a DataTable or List<>.

    If you'll be working at all with CSV, it's worth checking out a CSV parser.

提交回复
热议问题