搜尋

首頁  >  問答  >  主體

錯誤:MySQL - 操作數應該包含1列。

<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 budings. . 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粉529245050P粉529245050498 天前468

全部回覆(1)我來回復

  • P粉710454910

    P粉7104549102023-07-25 11:53:11

    我對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();
                }

    回覆
    0
  • 取消回覆