Problems with submitting text to access database.ASP.NET C#

Posted by Arianule under ASP.NET on 5/4/2011 | Points: 10 | Views : 1139 | Status : [Member] | Replies : 2

I have been experiencing problems to add text from a text box into an access database. It is a long piece of text and when I keep it to 3 or 4 sentences it is inserted with no errors but as soon as it appears to be too long I get the following error...System.Data.OledbException syntax error (missing operator)in the query expression. I have a method in the web service which adds the information and it is with the length of the one textbox insersiont(in this case a review to a book) that causes the error.

Another odd feature to the web page is that the submit button fires only upon the second click...there is a post back on the first click and then only on the second click does the information actually insert into the databse. I do not think however that this is the reason for the initial error of not being able to insert a paragraph into the access database(the field of which I have set to memo).

Any possibility to shed some light as to why the error is occuring. here is my actuall web method.

public void bookRatedAdd(string title, int rating, string review, string ISBN, string userName)
OleDbConnection conn;
conn = new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;
Data Source=" + Server.MapPath("App_Data\\BookRateInitial.mdb"));


OleDbCommand cmd = conn.CreateCommand();

cmd.CommandText = @"INSERT INTO bookRated([title], [rating], [review], [frnISBN], [frnUserName])VALUES('" + title + "', '" + rating + "','" + review + "','" + ISBN + "', '" + userName + "')";

It is with review where I get the error, the field of which I set to memo(in the access database).

kind regards Arian


Posted by: SheoNarayan on: 5/4/2011 [Administrator] HonoraryPlatinum | Points: 25

Hi Arian,

Looks like the problem is in your SQL Statement, you are not using parameterized statement that is causing error when you might be entering some text that contains single quote or any other special characters.

Use parameterized statement to execute your SQL statement.

Read this article Insert method and download the sample that contains enough info on how to do it


Sheo Narayan

Arianule, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arianule on: 5/5/2011 [Member] Starter | Points: 25

Thanks for the advice...will do that.

Arianule, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response