在插入查询中显示语法错误........... 错误
Syntax error in INSERT INTO statement.
但我检查了查询并对其进行了测试但是没有错误我的代码下面是否有任何问题...........请提前帮助谢谢
Sub OnOk()
Dim strquerry2 As String
Dim regcommand As OleDbCommand
Try
struser = txtuser.Text
strpwd = txtpwd.Text
strusertype = cmbbxutype.Text
If openconnection() Then
strquerry2 = "INSERT INTO Users(UserName , Password , UserType) VALUES('" & struser & "','" & strpwd & "','" & strusertype & "')"
regcommand = New OleDbCommand(strquerry2, strcon)
regcommand.ExecuteNonQuery()
End If
strcon.Close()
Catch ex As Exception
MessageBox.Show(ex.Message & " " & ex.Source)
End Try
End Sub
答案 0 :(得分:0)
很抱歉给您带来不便.........上面的代码不是一个难以理解的格式
Sub OnOk()
Dim strquerry2 As String
Dim regcommand As OleDbCommand
尝试
struser = txtuser.Text
strpwd = txtpwd.Text
strusertype = cmbbxutype.Text 一世 f openconnection()然后
strquerry2 =“INSERT INTO Users(UserName,Password,UserType)VALUES('&amp; struser&amp;”','“&amp; strpwd&amp;”','“&amp; strusertype&amp;”')“< / p>
regcommand = New OleDbCommand(strquerry2,strcon)
regcommand.ExecuteNonQuery()
结束如果
strcon.Close()
抓住ex Exception
MessageBox.Show(ex.Message&amp;“”&amp; ex.Source)
结束尝试
End Sub
答案 1 :(得分:0)
密码显然是一个保留字。在它周围放置方括号[]。
strquerry2 = "INSERT INTO Users(UserName , [Password] , UserType) VALUES('" & struser & "','" & strpwd & "','" & strusertype & "')"