By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,417 Members | 1,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,417 IT Pros & Developers. It's quick & easy.

syntax error in insert into statement.

P: 1
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

Expand|Select|Wrap|Line Numbers
  1. "Insert into Enter_Attendence(Course,Subject,Month,Date,Year,Semester,Day/Parttime,Nameofstudent) values('"
  2.  
  3. 'this is my insert into statement.
  4.  
  5.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  6.  
  7.         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)
  8.  
  9.         cmd.ExecuteNonQuery()
please anyone help me I can't find what is the error/errors.
Oct 7 '12 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,382
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.
Oct 7 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.