执行我的代码将数据插入到我的数据库时,我收到以下错误:错误插入数据到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