该程序在运行MS Office 2007的Windows XP上运行良好,但在运行MS Office 2007的Windows 7上运行不佳。所以我决定使用Microsoft.Ace,所以我使用了这个connectionString:
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=\"" + strDir + "\\\";"
+ "Extended Properties=\"text;HDR=YES;IMEX=1\"";方法如下:
public DataTable Load(string path, int columnCount)
{
CreateSchema(path, columnCount);
DataTable dtData = new DataTable();
string fullPath = Path.GetFullPath(path);
string csvFile = Path.GetFileName(fullPath);
string directoryName = Path.GetDirectoryName(fullPath);
string query;
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=\"" + directoryName + "\\\";"
+ "Extended Properties=\"text;HDR=YES;IMEX=1\"";
query = "SELECT * FROM " + csvFile;
OleDbDataAdapter dtAdapter = new OleDbDataAdapter(query, connString);
dtAdapter.Fill(dtData);
dtAdapter.Dispose();
return dtData;
}我的主要问题是,当我使用以下connectionString时,该程序可以在运行MS Office2007的Windows XP中运行,但不能在运行MS Office2007的Windows7中运行:
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=\"" + strDir + "\\\";"
+ "Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";我想出了我的研究,我需要使用ACE,所以我使用了这个connectionString:
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;"
+ "Data Source=\"" + strDir + "\\\";"
+ "Extended Properties=\"text;HDR=YES;IMEX=1\"";但还是没有用。请帮帮我!谢谢!
发布于 2013-04-15 15:55:32
这两个连接字符串用于不同类型的文件。
第一个是文本文件,第二个是Excel2007
第一个文件使用目录名作为DataSource,
第二个文件需要在strDir上输入Excel文件的名称
请参阅connectionstrings for Excel2007和connectionstrings for Text Files
这可能是您现在在ACE上出现错误的原因。
关于XP上的错误,我只能假设它与缺少JET/ACE驱动程序有关。在这种情况下,问题是由于您为其编译应用程序的平台造成的。请看this question and related answer
https://stackoverflow.com/questions/16010121
复制相似问题