1

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

2 Answers 2

2

Number is reserved word,

INSERT INTO [Student] ([StudentName], [Number], [Gender]) VALUES(@Name,@Number,@Gender)
Sign up to request clarification or add additional context in comments.

1 Comment

THis works after long time to search a solution for "has a syntax problem"
1

Seems like the Problem with field name "Number", its a keyword in MSAccess - http://support.microsoft.com/kb/286335.

1 Comment

I did not remember that there was a list of reserve keyword. I just work with access for 2 or 3 times before so thank you very much Anuraj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.