【发布时间】:2019-01-21 04:47:27
【问题描述】:
我正在尝试更新数据库表并收到错误
"MySql.Data.MySqlClient.MySqlException: '你的 SQL 有错误 句法;检查与您的 MySQL 服务器版本相对应的手册 在 'group='superadmin' WHERE 附近使用正确的语法 identifier='steam:steam:1100001098b5888'' 在第 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;
}
}
【问题讨论】:
-
请向我们展示您正在更新的表的架构(列类型)。
-
它们都是字符串,除了 job_grade 是一个 int。不是这样,我可以很好地获取信息,但不知何故我的更新出了点问题。