i have button add and the coding, but everytime 1 click the button, a messagebox said that syntax error INSERT INTO. all database column name and the textbox name is true. i checked many times. this is my code

Try
            'add data inside the database
            con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Bengkel\Project\db.mdb")
            con.Open()
            cmd = New OleDbCommand("INSERT into book (bookid,title,author,dateB,category,price,qty,image,status) VALUES('" & Me.bookid.Text & "','" & Me.title.Text & "','" & Me.author.Text & "','" & Me.datebook.Text & "','" & Me.cat.Text & "','" & Me.bookprice.Text & "','" & Me.qty.Text & "','" & Me.txtFilePathStaff.Text.ToString & "' ,'" & Me.stat.Text & "')", con)

            Dim ConfirmAdd As System.Windows.Forms.DialogResult
            ConfirmAdd = MessageBox.Show("Are You Sure Want To Add Data?", "Add", MessageBoxButtons.YesNo, MessageBoxIcon.Question)

            If ConfirmAdd = System.Windows.Forms.DialogResult.Yes Then
                a = cmd.ExecuteNonQuery()
                MessageBox.Show("Data Saved ", "Save")
                PBStaffPic.Image = Nothing
                bookid.Clear()
                title.Clear()
                author.Clear()
                datebook.Clear()
                cat.Text = ""
                bookprice.Clear()
                qty.Clear()
                stat.Text = ""
                PBStaffPic.Image = Nothing



            End If



        Catch ex As System.Exception
            MessageBox.Show(ex.Message)

        End Try
        con.Close()

note : i also use this code on other form, but it work. only this form got error. is my database table(book) got some problems?

In order to debug where the problem is, I will suggest:
1) Just before the ExecuteNonQuery take the Command string content and paste it into a new View (using SQL) in the Access DB and try it. If there is any syntax error ACCESS will help you do find where.
2) Do not surround with apostrophes the numeric fields
3) If there is a date field, be careful with the format passed to ACCESS

Hope this helps

thanks. i know the problem, one of my column name is image. image is one of List of reserved words in Jet 4.0. so thats why i got syntax error.

thanks by the way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.