How to use SQL against a CSV file

后端 未结 5 1980
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 11:04

I would like to use a SQL query on a CSV file using C#. There is something like this for java here. Is there anything like this for c#?

5条回答
  •  一个人的身影
    2021-01-12 11:32

    You can use Openrowsets .

    Enable SQL Ad Hoc/Openrowset in SQL configuration first. Once enabled you'll be able to connect your SQL Server Managerment studio and query Excel and comma delimited files.

    Your queries will look something like:

    SELECT * FROM OPENROWSET('MSDASQL','Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir={your path}','SELECT * FROM ypurtextfile.csv')
    

    You can use these queries in your C# code just like you query any other tables. Just check with your manager that he's ok with you enabling ad hoc on the SQL Server

提交回复
热议问题