开发者

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

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 OleDbPa开发者_如何学运维rameter("@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


There is a . (period) instead of a , (comma) in your INSERT statement after the @rating parameter.

Change the . to comma.

INSERT INTO bookRated([title], [rating], [review], [frnISBN], [frnUserName])
VALUES(@title, @rating, @review, @ISBN, @userName)


I think this may be as simple as that a period has been put in place of a comma where the parameters are specified:

@rating. @review

should be:

@rating, @review

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜