我正在尝试删除列,但我不断收到以下错误:
MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXISTS(DELETE 1 FROM
stock
WHEREsteamId
= 'MyIDGoesHere' ANDstock
=' at line 1
我的代码:
command.CommandText = "DELETE EXISTS(DELETE 1 FROM `" + Main.Instance.Configuration.Instance.DatabaseTableName + "` WHERE `steamId` = '" + id + "' AND `stock` = '" + stock + "' LIMIT 1);";
请帮我解决这个问题。谢谢!
最佳答案
这就是您删除符合条件的第一条记录的方式。正如其他人提到的,最好使用我也做过的参数:
command.CommandText = "DELETE FROM `" + Main.Instance.Configuration.Instance.DatabaseTableName + "` WHERE `steamId` = @SteamId AND `stock` = @Stock LIMIT 1;";
command.Parameters.AddWithValue("@SteamId", steamId);
command.Parameters.AddWithValue("@Stock", stock);
关于C# 和 MySQL : Delete Exists,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43191212/