-5
我怎樣才能擺脫這個「查詢表達式中的字符串中的語法錯誤」2333「erorr?更新語句的正確查詢是什麼?
con.Open();
OleDbCommand dt = new OleDbCommand("UPDATE AccRec SET Quantity=" + txtQuantity2.Text + ", Unit=" + txtUnit2.Text + " ,Company=" + txtCompany2.Text + ", Description=" + txtDesc2.Text + ", Amount='" + txtAmt2.Text + " Where No=" + textBox1.Text +"",con);Where No=5'.
dt.ExecuteNonQuery();
MessageBox.Show("updated");
OleDbDataAdapter da = new OleDbDataAdapter("SELECT * From AccRec ", con);
DataTable ds = new DataTable();
da.Fill(ds);
dataGridView2.DataSource = ds;
con.Close();
看到'如果沒有= 5''?你不能這樣做。 –
[SQL注入警報](http://msdn.microsoft.com/en-us/library/ms161953%28v=sql.105%29.aspx) - 你應該**不**連接你的SQL語句 - 使用**參數化查詢**,而不是爲了避免SQL注入 –
[從SELECT使用SQL Server更新]的可能重複(http://stackoverflow.com/questions/2334712/update-from-select-using-sql-server) –