执行我的代码以将数据插入数据库时,我收到以下错误:
system.data.oledb.oledbexception(0X80040E14):插入语法错误 进入声明
这是我的代码:
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()
答案 0 :(得分:0)
您在字段列表中缺少右括号。这样:
Insert into Parts
(Part, [Part ID],Manufacturer,Prices,[Manufacturer ID],[Part Description]
VALUES
(?,?,?,?,?,?)
应该是这样的:
Insert into Parts
(Part, [Part ID],Manufacturer,Prices,[Manufacturer ID],[Part Description])
VALUES
(?,?,?,?,?,?)