错误:MySQL - 操作数应该包含1列。
P粉529245050
P粉529245050 2023-07-24 18:17:13
0
1
463
<p>这个查询在我直接在MySQL中输入时可以工作,但在C#中却不行。</p> <pre class="brush:php;toolbar:false;">double deltaTime = (DateTime.Now - collectTime).TotalSeconds; string query = String.Format("UPDATE buildings LEFT JOIN server_buildings ON buildings.global_id = server_buildings.global_id AND buildings.level = server_buildings.level SET buildings.storage = buildings.storage + (server_buildings.speed * {0} * IF(buildings.boost >= NOW(), 2, 1)) WHERE buildings.global_id IN('generator', 'test')", deltaTime / 3600d);</pre> <p>只是得到了错误MySQL - 操作数应该包含1列。感谢建议! :)</p><p>预计随着时间的推移,它会在"storage"中增加值。</p><p><br /></p>
P粉529245050
P粉529245050

全部回复(1)
P粉710454910

我对MySQL还比较新。这是带有参数的查询。

string query = String.Format("UPDATE buildings JOIN server_buildings ON buildings.global_id = server_buildings.global_id AND buildings.level = server_buildings.level SET buildings.storage = buildings.storage + (server_buildings.speed * ?Num * IF(buildings.boost >= NOW(), 2, 1)) WHERE buildings.global_id IN('generator', 'test')");
                     
            using (MySqlCommand command = new MySqlCommand(query, connection))
            {
                MySqlParameter param = new MySqlParameter("?Num", (deltaTime / 3600d));
                command.Parameters.Add(param);
      
               command.ExecuteNonQuery();
            }
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板