我试图更新我的 mysql 数据库,但它不起作用并显示错误。
代码:
string constring = "datasource=localhost;port=3306;username=root;password=root";
string Query = "update database.check set namethestore = '" + this.textBox65.Text + "' , checkername= '" + this.textBox66.Text + "' , where namethestore = '" + this.textBox65.Text + "' ;";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
MySqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
MessageBox.Show("saved");
while (myReader.Read())
{
}
最佳答案
该代码有很多错误。
- 您应该对更新语句使用 ExecuteNonQuery
- 您必须使用参数化查询来保护您的代码免遭 SQL 注入(inject)
- 正如拉胡尔所说,你有一个额外的,
- 我想知道您最后是否要关闭连接。
关于c# - 更新mysql数据库导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24587550/