gpt4 book ai didi

C# SQL : update with params - getting 0 and without the text

转载 作者:行者123 更新时间:2023-11-28 23:17:25 25 4
gpt4 key购买 nike

我正在为我的解决方案制作 DatabaseManager 类,当我尝试更新文本时得到数字 0。例如:我现在有了 michael 这个名字,我想将其更改为“michael,mike”,所以我可能会使用更新。

public void AddCrime(CSteamID id, string crime, string time)
{
try
{
MySqlConnection connection = createConnection();
MySqlCommand command = connection.CreateCommand();
crime = "," + crime;
command.CommandText = "update `" + Main.Instance.Configuration.Instance.DatabaseTableName
+ "` set `crime` = crime + ( @crime ) where `steamId` = @steamID; select `crime` from `"
+ Main.Instance.Configuration.Instance.DatabaseTableName
+ "` where `steamId` = @steamID";
command.Parameters.AddWithValue("@steamID", id);
command.Parameters.AddWithValue("@crime", crime);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
AddTime(id, time);
}
catch (Exception ex) { Logger.Log(ex); }
}

如何调用它:

DatabaseManager.AddWanted(player.CSteamID, command[1], command[2]);

谢谢大家!

最佳答案

您命令中的最后一句是选择语句,NonQuery 不返回值,仅返回受影响的行数。将其更改为 ExecuteScalar 并将选择的值存储在变量中。

第二个错误是参数@steamID的数据类型。您设置值 id,声明为 CSteamID id... CStreamId 不是 string,更改AddWithValue

关于C# SQL : update with params - getting 0 and without the text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43257286/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com