0
我正在上傳一個Excel工作表,並希望將其數據移動到數據庫中的另一個表。最近兩天我得到一個錯誤(System.Data.OleDb.OleDbException invalid argument
),但是,如果我設計一個非常簡單的應用程序,它工作正常。請幫我System.Data.OleDb.OleDbException無效的參數
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("TERAMSConnectionString").ConnectionString) Dim path As String = FileUpload1.PostedFile.FileName Dim excelConnectionString As String = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + (path + ";Extended Properties=Excel 12.0;Persist Security Info=False")) Dim excelConnection As OleDbConnection = New OleDbConnection(excelConnectionString) conn.Open() excelConnection.Open() Dim cmd As OleDbCommand = New OleDbCommand("Select * from [Sheet1$]", excelConnection) 'Clears any previous data Dim sClearSQL = "DELETE FROM Desktop_Compare " Dim SqlCmd As SqlCommand = New SqlCommand(sClearSQL, conn) SqlCmd.ExecuteNonQuery() Dim dReader As OleDbDataReader = cmd.ExecuteReader Dim sqlBulk As SqlBulkCopy = New SqlBulkCopy(conn) excelConnection.Close() conn.Close() End Using Line 74: Dim excelConnection As OleDbConnection = New OleDbConnection(excelConnectionString) Line 75: conn.Open() Line 76: **excelConnection.Open()** Line 77: Dim cmd As OleDbCommand = New OleDbCommand("Select * from [Sheet1$]", excelConnection) Line 78: 'Clears any previous data
您在哪一點得到異常?作爲一個便箋,我會推薦使用'&'來連接字符串而不是'+'(我看到+導致一些奇怪的問題,因爲它試圖將字符串「添加」到一起而不是連接它們) – Grahamvs
@Grahamvs好的,我得到錯誤在「excelConnection.Open()」告訴用戶代碼是未處理的。 – Miank