当我尝试cmd.ExecuteNonQuery()
时,我收到错误提示“INSERT INTO语句中的语法错误”。
我发布了同样的问题yesterday ...有人可以再帮我一次吗?
Private Sub btnadd1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd1.Click
Dim cmd As New OleDb.OleDbCommand
Dim Printlist1 As New DataTable
If Not con.State = ConnectionState.Open Then
con.ConnectionString = "Provider=Microsoft.Ace.OLEDB.12.0; Data Source=c:Database11.accdb"
con.Open()
cmd.Connection = con
End If
If Me.text1.Tag & "" = "" Then
cmd.CommandText = "INSERT INTO Printlist1(StickerCode, Description, Company, Department, Location, User, SerialNumber, DatePurchased, Tagable, Quantity, Brand, Model)" & _
" VALUES(@StickerCode, @Description, @Company, @Department, @Location, @User, @SerialNumber, @DatePurchased, @Tagable, @Quantity, @Brand, @Model)"
cmd.Parameters.AddWithValue("@StickerCode", Me.text1.Text)
cmd.Parameters.AddWithValue("@Description", Me.text2.Text)
cmd.Parameters.AddWithValue("@Company", Me.text3.Text)
cmd.Parameters.AddWithValue("@Department", Me.text4.Text)
cmd.Parameters.AddWithValue("@Location", Me.text5.Text)
cmd.Parameters.AddWithValue("@User", Me.text6.Text)
cmd.Parameters.AddWithValue("@SerialNumber", Me.text7.Text)
cmd.Parameters.AddWithValue("@DatePurchased", Me.text8.Text)
cmd.Parameters.AddWithValue("@Tagable", Me.text9.Text)
cmd.Parameters.AddWithValue("@Quantity", Me.text10.Text)
cmd.Parameters.AddWithValue("@Brand", Me.text11.Text)
cmd.Parameters.AddWithValue("@Model", Me.text12.Text)
cmd = New OleDbCommand(cmd.CommandText, con)
cmd.ExecuteNonQuery()
Else
cmd.CommandText = "UPDATE Printlist1 " & _
" SET StickerCode='" & Me.text1.Text & _
", Description='" & Me.text2.Text & "'" & _
", Company='" & Me.text3.Text & "'" & _
", Department='" & Me.text4.Text & "'" & _
", Location='" & Me.text5.Text & "'" & _
", User='" & Me.text6.Text & "'" & _
", SerialNumber='" & Me.text7.Text & "'" & _
", DatePurchased='" & Me.text8.Text & "'" & _
", Tagable='" & Me.text9.Text & "'" & _
", Quantity='" & Me.text10.Text & "'" & _
", Brand='" & Me.text11.Text & "'" & _
", Model='" & Me.text12.Text & "'" & _
" WHERE text1=" & Me.text1.Tag
cmd.ExecuteNonQuery()
End If
RefreshData()
Me.btnclear1.PerformClick()
con.Close()
End Sub
贴纸代码说明公司部门位置用户序列号日期购买可标记数量品牌型号
答案 0 :(得分:3)
用户是Sql中的保留字,请尝试将其放在Square Brackets中,如[User]
cmd.CommandText = "INSERT INTO Printlist1(StickerCode, [Description], Company, Department, Location, [User], SerialNumber, DatePurchased, Tagable, Quantity, Brand, Model)" & _
" VALUES(@StickerCode, @Description, @Company, @Department, @Location, @User, @SerialNumber, @DatePurchased, @Tagable, @Quantity, @Brand, @Model)"