0

I used this code, but it shows fatal error and didn't give any information about error.

Fatal error encountered during command execution.

MySql.Data.MySqlClient.MySqlException was unhandled by user code Message=Fatal error encountered during command execution. Source=MySql.Data ErrorCode=-2147467259 Number=0 StackTrace:

Here is my code. I didn't show "connect" code because I call from outside. It worked fine with previous query method.

public int insertRateToDB(string tableName, double rate, int cid, int subGroup)
{         
    sql = "UPDATE " + tableName + " SET rate = @rate, subGroup = @subGroup WHERE id = @cid;";
    MySqlCommand cmd = new MySqlCommand(sql,connect);
    cmd.Prepare();
    cmd.Parameters.AddWithValue("@percent", rate);
    cmd.Parameters.AddWithValue("@subGroup", subGroup);
    cmd.Parameters.AddWithValue("@cid", cid);
    int result = cmd1.ExecuteNonQuery();
    return result;
}
4

1 回答 1

4

You need @rate parameter in the list not @percent

//cmd.Parameters.AddWithValue("@percent", rate);
cmd.Parameters.AddWithValue("@rate", rate);
于 2012-12-18T10:53:15.090 回答