syntax error in insert into statement.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abcnil
    New Member
    • Oct 2012
    • 1

    syntax error in insert into statement.

    I am using ms access 2010 database for my vb.net application. when I run the insert into statement it gives me erro in OleDb exeption was unhandled syntax error in INSERT INTO statement. when I run the query in SQL view in ms access it shows the error in

    Code:
    "Insert into Enter_Attendence(Course,Subject,Month,Date,Year,Semester,Day/Parttime,Nameofstudent) values('"
    
    'this is my insert into statement.
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
    
            cmd = New OleDbCommand("Insert into Enter_Attendence(Course,Subject,Month,Date,Year,Semester,Day/Parttime,Nameofstudent) values('" & ComboBox1.SelectedItem & "','" & ComboBox5.SelectedItem & "','" & ComboBox6.SelectedItem & "',#" & ComboBox7.SelectedItem & "#,'" & ComboBox2.SelectedItem & "','" & ComboBox3.SelectedItem & "','" & ComboBox4.SelectedItem & "','" & CheckedListBox1.CanSelect & "')", con)
    
            cmd.ExecuteNonQuery()
    please anyone help me I can't find what is the error/errors.
    Last edited by zmbd; Oct 7 '12, 05:40 AM. Reason: Please use the <CODE/> button to format HTML, VBA, PHP, JAVA, SQL, or other such information.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please use code tags when posting code.

    When you use non-standard characters in the name of a field, you need to demarcate them as such with square brackets. If you have anything other than letters, numbers, and underscores, then it's a nonstandard character.

    Therefore, when referring to Day/Parttime, you need to use [Day/Parttime].

    Also, if you use reserved key words, such as Year or Month or Left, you may also need to demarcate them.

    Comment

    Working...