我测试没有问题。或者可以改改代码:……
If dlg.ShowDialog = DialogResult.OK Then
If Connections.Contains("临时连接") Then '连接要导入的Excel
If DataTables.Contains("临时表") Then DataTables.Unload("临时表")
Connections.Delete("临时连接")
End If
If dlg.FileName.EndsWith(".xlsx")
Connections.Add("临时连接", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dlg.FileName & ";Extended Properties='Excel 8.0;HDR=yes'")
Else
Connections.Add("临时连接", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dlg.FileName & ";Extended Properties='Excel 8.0'")
End If
……
其次下载安装下面的数据访问组件:
http://www.foxtable.com/download/AccessDatabaseEngine.exe