Syntax error when Insert to Access using OleDb
I do not have a lot of experience in vb.net, but I am trying to use OleDB to insert a record with String,string,Yes/no(studentname, number, gender). However when I insert it , there's a exception raised stating that I have开发者_开发知识库 invalid syntax for the "insert into" query. I could not spot the error.
Test case:
txtName.Text = "asdasdasd"
txtPhone.Text = "123456789"
rGender.Checked = True
Here's the code:
cmd = New OleDbCommand()
With cmd
.Connection = cn
.CommandText = "INSERT INTO [Student] (StudentName, Number, Gender) VALUES(@Name,@Number,@Gender)"
.CommandType = CommandType.Text
.Parameters.AddWithValue("@Name", txtName.Text)
.Parameters.AddWithValue("@Number", txtPhone.Text)
.Parameters.AddWithValue("@Gender", rGender.Checked)
End With
Seems like the Problem with field name "Number", its a keyword in MSAccess - http://support.microsoft.com/kb/286335.
Number is reserved
word,
INSERT INTO [Student] ([StudentName], [Number], [Gender]) VALUES(@Name,@Number,@Gender)
精彩评论