0

你好,我有問題,從微軟訪問2013年運行更新查詢我只是想更新與客戶端ID和名稱和手機客戶端表我不能得到數據要更新總是語法錯誤更新查詢從微軟訪問數據庫中讀取

string I = "UPDATE client SET client.ID =" + ID.Text + " ,client.Name =" + Name.Text + " ,client.Phone = " + Phone.Text + " WHERE client.ID="+ ID.Text +""; 
      command.CommandText = I; 
      command.CommandType = CommandType.Text; 
      connection.Open(); 
      command.ExecuteNonQuery(); 

回答

0

您需要使用參數化查詢,像這樣:

string I = "UPDATE client SET client.Name = ?, client.Phone = ? WHERE client.ID = ?"; 
command.CommandText = I; 
command.CommandType = CommandType.Text; 
command.Parameters.AddWithValue("?", Name.Text); 
command.Parameters.AddWithValue("?", Phone.Text); 
command.Parameters.AddWithValue("?", ID.Text); 
connection.Open(); 
command.ExecuteNonQuery(); 

注意,這是沒有意義的「SET」 client.ID因爲它不會改變。