0

Additional information: Syntax error (missing operator) in query expression ''1')'.

This is my code

Dim connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= Database1.mdb;")
Dim command As New OleDbCommand("INSERT INTO Student_Enquiry (StudentID,Email,Receiver,Comment) VALUES('" + TextBox3.Text + "','" + TextBox1.Text + "','" + ComboBox1.Text + "', '" + TextBox4.Text + "')", connection)

command.Connection.Open()
command.ExecuteNonQuery()
command.Connection.Close()

1 Answer 1

2

The issue is that the final closing parenthesis in the insert statement actually isn't a normal Right Parenthesis; it is a different character.

You used - "Fullwidth Right Parenthesis", U+FF09
instead of ) - "Right Parenthesis", U+0029, ASCII 0x29

Compare the the invalid and the valid: != )

Use this instead:

Dim command As New OleDbCommand("INSERT INTO Student_Enquiry (StudentID,Email,Receiver,Comment) VALUES('" + TextBox3.Text + "','" + TextBox1.Text + "','" + ComboBox1.Text + "', '" + TextBox4.Text + "')", connection)

Also, you really shouldn't inject values into the query but rather use parametrized queries to avoid issues with potential SQL injection etcetera. The documentation shows you how to do this.

Sign up to request clarification or add additional context in comments.

8 Comments

@GordThompson Thanks for the edit, I was wondering what the invalid character actually was; it evaluated as ascii 41 in MSSQL just as a normal right parenthesis.
Thanks for you all help me! ) != ) <<< like this error also can found it. PRO! I love you all !
But one more question... how about the update code? Is it UPDATE Student_Enquiry something like this??
@meili Yes. The basic syntax for update is update your_table set your_column = new_value.
@jpw currently my system need to if i edit my studentID then will update the studentID.... i'm just code : UPDATE Student_Information SET StudentID='"+Textbox1.text+"' WHERE StudentID = "" Am i correct?
|

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.