gpt4 book ai didi

C# MySql 0x80004005) : an error in SQL syntax;

转载 作者:行者123 更新时间:2023-11-29 05:07:20 29 4
gpt4 key购买 nike

我的代码偶尔会出错(windows 服务)。我用了断点,但是什么也没有。谁能帮帮我

 private void SetGPSIsLogOut(int shopId,int status)
{
MySqlConnection conn = ConnectDataBase();
strcmd.Clear();
strcmd.AppendLine("update multi_shop_gps_location_log set gps_is_logout="+status+" where shop_id=" + shopId + " ");
MySqlCommand myCommand = new MySqlCommand(strcmd.ToString());
myCommand.Connection = conn;
try
{
conn.Open();
myCommand.ExecuteNonQuery();
conn.Close();
}
catch (MySqlException e)
{
UpdateServicestatus(-1);
WriteLog("SetGPSIsLogOut 更新失败" + e);
}
}

异常(exception):

MySql.Data.MySqlClient.MySqlException (0x80004005): 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 'update multi_shop_gps_location_log set gps_is_logout=0 where shop_id=513' at line 2 在 MySql.Data.MySqlClient.MySqlStream.ReadPacket() 在 MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId) 在 MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId) 在 MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force) 在 MySql.Data.MySqlClient.MySqlDataReader.NextResult() 在 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) 在 MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() 在 ys_service.Service1.SetGPSIsLogOut(Int32 shopId, Int32 status) 位置 E:\service\service\Service1.cs:行号 645

帮助

最佳答案

错误是由于您没有在连接的查询字符串上使用引号引起的。

但是正确的方法是使用参数而不是字符串连接:

...
string query ="update multi_shop_gps_location_log set gps_is_logout=@status where shop_id=@shopId";
MySqlCommand myCommand = new MySqlCommand(query);
myCommand.Parameters.Add("@status",status);
myCommand.Parameters.Add("@shopId ",shopId );
...

关于C# MySql 0x80004005) : an error in SQL syntax;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45609170/

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