当我首先尝试阅读.xls
和.xlsx
秒时,我收到此错误。
我正在使用的连接字符串是:
public string GetConnectionString(string DataFile)
{
Dictionary<string, string> props = new Dictionary<string, string>();
string extension = System.IO.Path.GetExtension(DataFile);
props["Provider"] = "Microsoft.ACE.OLEDB.12.0;";
if (extension == ".xlsx")
props["Extended Properties"] = "Excel 12.0;";
else
props["Extended Properties"] = "Excel 8.0;";
props["Data Source"] = DataFile;
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<string, string> prop in props)
{
sb.Append(prop.Key);
sb.Append('=');
sb.Append(prop.Value);
sb.Append(';');
}
return sb.ToString();
}
有人可以帮我解决这个问题吗?