我在更新代码中有以下错误:
错误 > SQL 语法; 检查 对应的手册 您的 MSQL 服务器 版本 < em> 正确 语法 到 _use _near'(其中Aid ='3'在'1'行< / EM> 这是代码
private void button2_Click(object sender, EventArgs e)
{
try
{
//This is my connection string i have assigned the database file address path
string MyConnection2 = "datasource=localhost;port=3307;username=root;password=root";
//This is my update query in which i am taking input from the user through windows forms and update the record.
string Query = "update aircraft.l1201 set Name='" + this.nameTextBox.Text + "',Initials='" + this.piniTextBox.Text + "', where Aid='" + this.AidTextBox.Text + "';";
//This is MySqlConnection here i have created the object and pass my connection string.
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
MySqlDataReader MyReader2;
MyConn2.Open();
MyReader2 = MyCommand2.ExecuteReader();
MessageBox.Show("Data Updated");
while (MyReader2.Read())
{
}
MyConn2.Close();//Connection closed here
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 0 :(得分:3)
删除逗号
... , where Aid=...
^---here
你应该真的使用预备语句,而不是像这样一起修补你的查询。它也会更加安全。