System.Data.OleDb.OleDbException: Number of query values and destination fields are not the same. [Resolved]

Posted by Arianule under ASP.NET on 5/5/2011 | Points: 10 | Views : 2353 | Status : [Member] | Replies : 3
Hello

I received some help which I much appreciate to insert info into a database using paramaters as it is better practice I believe to do this.
I do however get the following error 'Number of query values and destination fields are not the same'. Not sure as to why it is happening.
The code seems perfectly fine and the database.

[WebMethod]
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"));

conn.Open();



OleDbCommand cmd = conn.CreateCommand();

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

//adding my parameters
cmd.Parameters.AddRange(new OleDbParameter[]
{
new OleDbParameter("@title", title),
new OleDbParameter("@rating", rating),
new OleDbParameter("@review", review),
new OleDbParameter("@ISBN", ISBN),
new OleDbParameter("@userName", userName),
});


cmd.ExecuteNonQuery();
conn.Close();
}

Advice perhaps as to why this error exist?

Kind regards
Arian




Responses

Posted by: T.saravanan on: 5/5/2011 [Member] [MVP] Silver | Points: 50

Up
0
Down

Resolved
Check this line..(@title, @rating. @review, @ISBN, @userName)";

change into (@title, @rating, @review, @ISBN, @userName)";

I think this is your mistake.




Thanks,
T.Saravanan

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

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

Up
0
Down
Thanks
I apologize for that
ragards


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

Posted by: Nishithraj on: 5/5/2011 [Member] Bronze | Points: 25

Up
0
Down
Arianule,

Please mark Saravanan's answer, if that's the solution.

Mark this as answer, if it is.....

With regards
Nishithraj Narayanan

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

Login to post response