我不知所措。我有这个代码在我的机器上正常运行并将csv加载到数据表:
public static DataTable GetDataTableFromCsv(string path, string sheetname, string header)
{
var directory = new DirectoryInfo(path);
var myFile = directory.GetFiles().Where(x => x.Name.ToLowerInvariant().Contains(sheetname.ToLowerInvariant())).OrderByDescending(f => f.LastWriteTime).First().Name;
string sql = @"SELECT * FROM [" + myfile+ "]";
using (OleDbConnection connection = new OleDbConnection(
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path +
";Extended Properties=\"Text;HDR=" + header + "\""))
using (OleDbCommand command = new OleDbCommand(sql, connection))
using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
{
DataTable dataTable = new DataTable();
dataTable.Locale = CultureInfo.InvariantCulture;
adapter.Fill(dataTable);
return dataTable;
}
}
这在我的机器上工作正常。但是在另一台机器上却没有。我用谷歌搜索并检查我们在同一个地方有相同版本的MSJet40.dll,我们都在64位机器上,但在机器上它不工作我没有视觉工作室所以我不能调试。 有什么想法吗?