Excel导入数据库失败
Dim openFile As New OpenFileDialog
Dim fileName As String
Dim filePath As String
Dim fileNameTemp As String
Dim txtSql As String = ""
Dim msgText As String = ""
Dim ExcelInput_DT As DataTable
Dim Excel_DT As DataTable
Dim tableName As String
'读出路径
RExInputInI()
If ExPath Is Nothing Then
openFile.Filter = "Excel文件(*.xls)|*.xls"
If openFile.ShowDialog = Windows.Forms.DialogResult.Cancel Then
MessageBox.Show("没有导入的Excel文件!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return
Else
filePath = openFile.FileName
End If
Else
filePath = ExPath
End If
fileNameTemp = Microsoft.VisualBasic.Right(filePath, filePath.Length - filePath.LastIndexOf("\") - 1)
fileName = Microsoft.VisualBasic.Left(fileNameTemp, fileNameTemp.Length - 4)
Dim conExcel As OleDb.OleDbConnection
Dim conString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & filePath & "; Extended Properties=Excel 8.0;"
Try
conExcel = New OleDb.OleDbConnection(conString)
conExcel.Open()
'获取excel表()
Excel_DT = conExcel.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, Nothing)
'获取sheet名,其中(0)(1)...(N): 按名称排列的表单元素
tableName = Excel_DT.Rows(0)(2).ToString().Trim()
tableName = "[" & tableName.Replace(" ' ", " ") & "]"
Catch ex As Exception
MessageBox.Show(ex.Message + "打开Excel出错!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
conExcel.Dispose()
End Try
Try
'就在这个地方,是不是我的SQL语句有问题。
txtSql = "insert into wblLabel select distinct * from [Excel 8.0;database=" + fileName + "]." + tableName + " where 品目コード not IN (select code from wblLabel)"
ExcelInput_DT = ExecuteSql(txtSql, msgText)
Catch ex As Exception
MessageBox.Show(ex.Message + "导入失败!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
我的Excel表也找到了,我把那就sql语句复制到查询分析器中也没有报错,但是执行到最后就报错了。说对象名'Excel8.0;database=EXCEL.SHEET$'无效。执行数据库操作失败!