Microsoft.ACE.OLEDB.12.0 CSV ConnectionString [英] Microsoft.ACE.OLEDB.12.0 CSV ConnectionString
问题描述
我知道这个问题不时被问,但我找不到任何满意的解决方案。
I know questions this kind are asked from time to time but i can't find any satisfying solution.
如何使用MS ACE OLEDB 12打开CSV文件?
我尝试下面的代码。
How can I open a CSV-File using MS ACE OLEDB 12? I try it with the following code.
DbConnection connection = new OleDbConnection();
connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Documents;Extended Properties=\"Text;HDR=Yes\"";
connection.Open();
DbCommand cmd;
cmd = connection.CreateCommand();
cmd.CommandText = "SELECT * FROM [Mappe1#csv]";
DbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
Console.Write("(" + reader.GetValue(i).ToString() + ")");
Console.WriteLine();
}
cmd.Dispose();
connection.Dispose();
Console.WriteLine("Done");
Console.ReadKey();
问题是只找到一列。文本由;分隔。即使当我指定分隔符与Delimited(|)f.e。
The Problem is that only one column is found. The Text is delimited by ';'. Even when i specifiy the delimiter with "Delimited(|)" f.e. it will not work.
我找不到此提供程序的任何文档...
I can't find any documentation for this provider...
推荐答案
这帮助我得到一个分号分隔的csv使用ACE.OLEDB.12.0在C#中解析:
http://sqlserverpedia.com/blog/sql-server-bloggers/use-ace- drivers-and-powershell-to-talk-to-text-files / :
This helped me getting a semicolon-delimited csv to parse in C# using ACE.OLEDB.12.0: http://sqlserverpedia.com/blog/sql-server-bloggers/use-ace-drivers-and-powershell-to-talk-to-text-files/:
创建 schema.ini 文本文件在与要导入的csv文件相同的目录中,使用以下内容:
Create a schema.ini text file in the same directory as the csv file you want to import with the following contents:
[fileIwantToImport.csv]
Format=Delimited(;)
ColNameHeader=True
但是太好了。
看起来像连接字符串中的 FORMAT = Delimited(;)
...
Seems like the FORMAT=Delimited(;)
in the connection string has gone out of fashion...
这篇关于Microsoft.ACE.OLEDB.12.0 CSV ConnectionString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!