'i got a problem here. i want to add a new record to my database but when i click the add button an error occurs saying syntax error on INSERT INTO statement. it is placed on the da.update(ds, "studentprofile")
what should i do?? here's the code:

       Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click

            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsnewrow As DataRow

            dsnewrow = ds.Tables("studentprofile").NewRow()

            dsnewrow.Item(1) = txtlastname.Text
            dsnewrow.Item(2) = txtfirstname.Text
            dsnewrow.Item(3) = txtmiddlename.Text
            dsnewrow.Item(4) = txtgender.Text
            dsnewrow.Item(5) = txtage.Text
            dsnewrow.Item(6) = txtlevel.Text
            dsnewrow.Item(7) = txtcourse.Text
            dsnewrow.Item(8) = txtaddress.Text
            dsnewrow.Item(9) = DateTimePicker1.Value
            dsnewrow.Item(10) = txtnationality.Text
            dsnewrow.Item(11) = txtplaceofbirth.Text
            dsnewrow.Item(12) = txtcivilstatus.Text
            dsnewrow.Item(13) = txtcontactnumber.Text
            dsnewrow.Item(14) = txtguardian.Text
            dsnewrow.Item(15) = txtrelationship.Text
            dsnewrow.Item(16) = txtguardiancontact.Text

            ds.Tables("studentprofile").Rows.Add(dsnewrow)

            da.Update(ds, "studentprofile")

            MsgBox("New record added.", MsgBoxStyle.Information)
            btnupdate.Enabled = True
        Else
            incdec = 0
            Dim cb As New OleDb.OleDbCommandBuilder(da)
            Dim dsnewrow As DataRow

            dsnewrow = ds.Tables("studentprofile").NewRow()


            dsnewrow.Item(1) = txtlastname.Text
            dsnewrow.Item(2) = txtfirstname.Text
            dsnewrow.Item(3) = txtmiddlename.Text
            dsnewrow.Item(4) = txtgender.Text
            dsnewrow.Item(5) = txtage.Text
            dsnewrow.Item(6) = txtlevel.Text
            dsnewrow.Item(7) = txtcourse.Text
            dsnewrow.Item(8) = txtaddress.Text
            dsnewrow.Item(9) = DateTimePicker1.Value
            dsnewrow.Item(10) = txtnationality.Text
            dsnewrow.Item(11) = txtplaceofbirth.Text
            dsnewrow.Item(12) = txtcivilstatus.Text
            dsnewrow.Item(13) = txtcontactnumber.Text
            dsnewrow.Item(14) = txtguardian.Text
            dsnewrow.Item(15) = txtrelationship.Text
            dsnewrow.Item(16) = txtguardiancontact.Text

            ds.Tables("studentprofile").Rows.Add(dsnewrow)

            da.Update(ds, "studentprofile")


            MsgBox("New record added.", MsgBoxStyle.Information)
            btnupdate.Enabled = True

        End If
    End Sub
end class

Did you happen to notice that the code as posted is incomplete? For example, even though it starts with Private Sub there is no opening If statement. That means some of the code was left out.

I did, but as they were a newbie I though they may have accidently left it out when they copied it over, it must be there in the actual code or else how could they compile the code to get the error?

I just get suspicious when I see things like that. It's unusual, when copying and pasting a block of code, to have one line in the middle left out. It makes me think that the copy/paste was done in two chunks with some other code, including the If, left out.

This article has been dead for over six months. Start a new discussion instead.