-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) –