在vb.net中創建應用程序以連接到Excel文件並對其進行編輯。向excel提出查詢時出現奇怪的錯誤
目前試圖修改Excel文件時,出現以下錯誤:
有了這個功能
Protected Friend Function obtenerHojaActual(ByVal columna As String, ByVal con As String) As String
Dim cmd As String
Dim WorkSheet As String = ""
Try
libro = app.Workbooks.Open(con)
For Each hoja As Microsoft.Office.Interop.Excel.Worksheet In libro.Worksheets
cmd = "SELECT [" & columna & "] FROM [" & hoja.Name & "$]"
Dim adapter As New OleDbDataAdapter(cmd, conexion)
Dim tabla As New DataTable
adapter.Fill(tabla)
adapter.Dispose()
//Code
//Code
//Code
tabla.Dispose()
Next
libro.Close()
app.Quit()
Return WorkSheet
Catch ex As Exception
repairmanMessage("Error inesperado", ex.Message, My.Resources._error).ShowDialog()
principal.lbldireccion.ForeColor = Color.Red
Return WorkSheet
End Try
End Function
得到這個:
「沒有指定的值對於一些所需的參數「
而與此:
Protected Friend Function obtenerErrores(ByVal columna As String, ByVal hoja As String, ByVal tipo As String) As Integer
Dim cmd As String = "SELECT [" & columna & "] FROM [" & hoja & "$]"
Dim errores As Integer = 0
Dim fecha As Date
Dim tabla As New DataTable
Try
Dim adapter As New OleDbDataAdapter(cmd, conexion)
adapter.Fill(tabla)
adapter.Dispose()
//Code
//Code
//Code
tabla.Dispose()
Return errores
Catch ex As Exception
repairmanMessage("Error inesperado", ex.Message, My.Resources._error).ShowDialog()
principal.lbldireccion.ForeColor = Color.Red
Return errores
End Try
得到這個錯誤...
我嘗試使用參數化查詢,但看起來像Excel中不要工作得很好用那個東西(也許,我不知道用於Excel的查詢的語法)。
最奇怪的是,在代碼的其他部分,不要給我錯誤,程序只是在我試圖修改文件時拋出錯誤,儘管我得到這兩個錯誤,但excel表單被修改就像我想要的那樣。
什麼可以是?
你在你的'Exception'對象有一個'InnerException'?那些通常會告訴你什麼參數丟失。 –
不...讓我添加它,看看 – TwoDent
我插入了你告訴我的內容,並打印出一個空白的msgbox ... – TwoDent