【问题标题】:MySQL query error in c#C#中的MySQL查询错误
【发布时间】:2015-03-24 08:24:15
【问题描述】:

当我从 Visual Studio C# 运行查询时

insert into nts1.empty_routes_mip 
select @rownum := @rownum + 1, station_from_id, station_to_id, nko_empty_run, cost, nko_min, nko_max, nko_ratio_1, nko_ratio_2 
from nts1.empty_routes, (SELECT @rownum := 0) r
where id in (select empty_route_id from nts1.empty_runs_made_lp);

我得到一个错误

MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during command execution. ---> MySql.Data.MySqlClient.MySqlException (0x80004005): Parameter '@rownum' must be defined.
в MySql.Data.MySqlClient.Statement.SerializeParameter(MySqlParameterCollection parameters, MySqlPacket packet, String parmName, Int32 parameterIndex)
в MySql.Data.MySqlClient.Statement.InternalBindParameters(String sql, MySqlParameterCollection parameters, MySqlPacket packet)
в MySql.Data.MySqlClient.Statement.BindParameters()
в MySql.Data.MySqlClient.PreparableStatement.Execute()
в MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
в MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
в MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()

谁能帮我解决一下?

【问题讨论】:

    标签: c# mysql executenonquery


    【解决方案1】:

    根据您发布的错误,我想说您没有定义变量@rownum,因此它无法执行查询。我不知道您是如何使用整个查询的,但由于它在 c# 中,您可能可以使用如下内容:

      <SQLcommand_name>.parameters.add("@parametername", SqlDbType.<variabletype>).Value = <variable value>;
    

    之间的东西要根据自己的数据库等来设置

    【讨论】:

      【解决方案2】:

      你忘了初始化@rownum

      insert into nts1.empty_routes_mip 
      SET @rownum:=0; /* YOUR MISTAKE*/
      select @rownum := @rownum + 1, station_from_id, station_to_id, nko_empty_run,cost, nko_min, nko_max, nko_ratio_1, nko_ratio_2 
      from nts1.empty_routes, (SELECT @rownum := 0) r
      where id in (select empty_route_id from nts1.empty_runs_made_lp);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-11-13
        • 1970-01-01
        • 1970-01-01
        • 2010-09-05
        • 2018-08-11
        • 2016-07-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多