我有一个窗口,需要导入excel到表里,但是只有第一次是成功的,后面同样的按钮紧接着再接着导入,会出现问题,说是找不到临时表Dim dlg As New OpenFileDialog
dlg.MultiSelect = False
dlg.Filter= "模板文件|*.xls;*.xlsx" '设置筛选器
dlg.InitialDirectory = SpecialFolder.DesktopDirectory '初始目录
If dlg.ShowDialog = DialogResult.OK Then
If Connections.Contains("临时连接") Then '连接要导入的Excel
If DataTables.Contains("临时表") Then DataTables.Unload("临时表")
Connections.Delete("临时连接")
End If
Connections.Add("临时连接", "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dlg.FileName & ";Extended Properties='Excel 8.0;HDR=yes'")
'--------接下来把所有的数据导入到临时表里----------------------
Dim q As new QueryBuilder
q.C
q.TableName = "临时表"
q.SelectString = "S elect * fr om [Sheet1$]"
q.Build
Dim t As Table = e.Form.Controls("Table1").Table
If DataTables.Contains("临时表")
t.DataSource = DataTables("临时表")
Else
End If
End If