【问题标题】:mysql fatal error, but i think i did every thing rightmysql致命错误,但我认为我做的每一件事都是正确的
【发布时间】:2012-12-18 10:51:39
【问题描述】:

我使用了这段代码,但它显示了致命错误并且没有提供任何有关错误的信息。

在命令执行过程中遇到致命错误。

MySql.Data.MySqlClient.MySqlException 未被用户代码处理 Message=Fatal error 在命令执行期间遇到。 Source=MySql.Data ErrorCode=-2147467259 Number=0 StackTrace:

这是我的代码。我没有显示“连接”代码,因为我是从外面打电话的。它与以前的查询方法配合得很好。

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;
}

【问题讨论】:

  • @rate 未定义为您的参数之一
  • 使用@rate iso@percent

标签: c# mysql sql


【解决方案1】:

列表中需要@rate 参数而不是@percent

//cmd.Parameters.AddWithValue("@percent", rate);
cmd.Parameters.AddWithValue("@rate", rate);

【讨论】:

  • 我现在改成“@rate”,我执行什么也没发生,是不是原来的sql有问题?? @kaf
  • @riseres : Call Prepare() method after setting the Commandtext and Parameters.try without it 请阅读此MSDN 链接了解更多详情
猜你喜欢
  • 1970-01-01
  • 2022-01-05
  • 2011-08-21
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 2020-04-23
相关资源
最近更新 更多