2017-06-19 18 views
-1

SQL語法,我已經在更新代碼以下錯誤:錯誤在行 '1' 使用C#

一個錯誤SQL語法;檢查手動對應MSQL服務器語法 _USE _near「(其中援助='3'at線「1」 下面是代碼

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

請格式化您的文章。它顯示了你的一些努力。 –

+0

請閱讀https://stackoverflow.com/a/30367283/34092 re:SQL注入。它今天不會解決你的問題 - 但它會爲你節省一生的痛苦。 – mjwills

回答

3

刪除逗號

... , where Aid=... 
    ^---here 

而且你應該使用預處理語句,而不是一起修補你這樣的查詢。而且它也會更安全。