執行我的代碼將數據插入到我的數據庫時,我收到以下錯誤:錯誤插入數據到SQL Server數據庫
system.data.oledb.oledbexception(0X80040E14):語法錯誤插入 into語句
這裏是我的代碼:
Public Sub put_data(ByVal lstpart As List(Of String), lstpartid As List(Of String), lstmanufacturer As List(Of String), lstmanufacturerid As List(Of String), lstprice As List(Of String), lstpartdescription As List(Of String), ByVal lstpartimg As List(Of Image))
Dim intCurrentRecord As Integer = 0
Dim strSQL As String
Dim ds As New DataSet
' Dim sqlcmd As OleDbCommand
MsgBox(MyCn.State.ToString, vbOK, "test")
Try
Do While intCurrentRecord <= lstpart.Count - 1
strSQL = "Insert into Parts (Part, [Part ID],Manufacturer,Prices,[Manufacturer ID],[Part Description] VALUES (?,?,?,?,?,?)"
strSQL = strSQL.Replace(vbCrLf, " ")
Using MyCn
Using sqlcmd = New OleDbCommand(strSQL, MyCn)
sqlcmd.Parameters.AddWithValue("@p1", lstpart(intCurrentRecord))
sqlcmd.Parameters.AddWithValue("@p2", lstpartid(intCurrentRecord))
sqlcmd.Parameters.AddWithValue("@p3", lstmanufacturer(intCurrentRecord))
sqlcmd.Parameters.AddWithValue("@p4", lstprice(intCurrentRecord))
sqlcmd.Parameters.AddWithValue("@p5", lstmanufacturerid(intCurrentRecord))
sqlcmd.Parameters.AddWithValue("@p6", lstpartdescription(intCurrentRecord))
sqlcmd.ExecuteNonQuery()
End Using
End Using
intCurrentRecord += 1
Loop
Catch ex As Exception
MsgBox(ex.ToString, vbOK, "Error")
End Try
dbclose()
格式代碼 – MrTux 2014-09-03 22:47:53
你必須在插入一個語法錯誤into語句。至少,列的列表缺少''''。 「使用MyCn」是否意味着'MyCn'將在'End Using'處處置?因爲你似乎正在重新使用'MyCn'('Do While ...')。 – 2014-09-03 22:48:14
好像你在列列表末尾缺少''''。 – 2014-09-03 22:48:18