gpt4 book ai didi

c# - MySQL 服务器错误 - 您的 SQL 语法有错误

转载 作者:行者123 更新时间:2023-11-29 09:53:46 25 4
gpt4 key购买 nike

我正在尝试更新数据库表并收到错误

"MySql.Data.MySqlClient.MySqlException: 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group='superadmin' WHERE identifier='steam:steam:1100001098b5888'' at line 1'"

        // Creates query to run
public void UpdateInfo(String jobTitle, int jobGrade, String adminLevel, String identifier) {

// Opens the database connection if it's not already open
if (!(databaseConnected)) {
openConnection();
}

// Creates query to run
String query = "UPDATE " + table + " SET job=@jobTitle, job_grade=@jobGrade, group=@adminLevel WHERE identifier=@identifier";

// Makes a new command
MySqlCommand cmd = new MySqlCommand(query, connection);

// Replaces the @ placeholders with actual variables
cmd.Parameters.AddWithValue("@jobTitle", jobTitle);
cmd.Parameters.AddWithValue("@jobGrade", jobGrade);
cmd.Parameters.AddWithValue("@adminLevel", adminLevel);
cmd.Parameters.AddWithValue("@identifier", identifier);

// Executes it and if it's...
if (cmd.ExecuteNonQuery() > 0) {
// Successful
MessageBox.Show("Successfully updated information");

closeConnection();
return;
} else {
// Not successful
MessageBox.Show("Error with updating information!");

// Closes the connection again to prevent leaks
closeConnection();
return;
}

}

最佳答案

我在 https://sqltest.net/ 上尝试了您的查询当我尝试创建表格时,注意到它突出显示了“组”。我想知道问题是否可能是使用“group”作为列名,因为它是保留字。

是否可以尝试将列重命名为 group_level 或在“group”或“group”周围添加反勾号,看看是否有效?

举个例子

'group'=@grouplevel

我找到了this threadthis thread on renaming the column他们对“group”作为列名有疑问。添加反引号似乎可以解决这两个问题。

编辑:根据OP,双引号(“)解决了问题而不是单引号。编辑后的答案包括在内。

关于c# - MySQL 服务器错误 - 您的 SQL 语法有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54283649/

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