tags:

views:

28

answers:

2

Showing Syntax error in Insert Query........... Error

           Syntax error in INSERT INTO statement.

but i have checked the query and tested it but there is no error Is there any problem in my code below...........Please any help thanks in advance

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
A: 

Sorry for inconvenience.........Above code was not in an uderstanable formate

Sub OnOk()

Dim strquerry2 As String

Dim regcommand As OleDbCommand

Try

struser = txtuser.Text

strpwd = txtpwd.Text

strusertype = cmbbxutype.Text I f 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

Buzdar
A: 

Password is apparently a reserved word. Place square brackets [] around it.

strquerry2 = "INSERT INTO Users(UserName , [Password] , UserType) VALUES('" & struser & "','" & strpwd & "','" & strusertype & "')"
Kelly Ethridge
Thanks Kelly............. Yes this was the real problem again thanks for your in time response
Buzdar