2017-06-12 66 views
-5

我得到這個SQLEXCEPTION:C#更新問題

附近有語法錯誤 ''。

newConnection.ConnectionM(); 
SqlCommand cmd = SqlConnectionOLTP.cn.CreateCommand(); 
cmd.CommandText = "Update Cost SET [email protected],[email protected], [email protected] where [email protected], [email protected], [email protected]"; 
cmd.Parameters.AddWithValue("@actualamount", textBoxAmount.Text); 
cmd.Parameters.AddWithValue("@flag", flag); 
cmd.Parameters.AddWithValue("@date", dateTimePickerDate.Text); 
cmd.Parameters.AddWithValue("@projectid", ProjectID); 
cmd.Parameters.AddWithValue("@propertyid", PropertyID); 
cmd.Parameters.AddWithValue("@costcategoryid", CostCatID); 
cmd.ExecuteNonQuery(); 
SqlConnectionOLTP.cn.Close(); 
MessageBox.Show("Saved", "Save", MessageBoxButtons.OK, MessageBoxIcon.None); 
+1

[閱讀它是有用的:

我與和下面條件下使用此細手冊](https://docs.microsoft.com/en-us/sql/t-sql/queries/where-transact-sql)瞭解如何指定WHERE條件。這不是用逗號。 –

+1

如果你有一個* SQL *異常,你應該發佈一個* SQL *問題,並且實際嘗試這個語句以確保它是正確的。在這個特殊情況下,SQL教程會更合適 –

+1

請用正確的標記和有效的標題重寫你的問題(C#問題不是一個有效的標題) –

回答

0

在條件應與OR或任何條件要應用分開的逗號。

newConnection.ConnectionM(); 
       SqlCommand cmd = SqlConnectionOLTP.cn.CreateCommand(); 
       cmd.CommandText = "Update Cost SET [email protected],[email protected], [email protected] where Projec[email protected] and [email protected] and [email protected]"; 
       cmd.Parameters.AddWithValue("@actualamount", textBoxAmount.Text); 
+2

Op在他的查詢中有非常基本的語法錯誤,這意味着他是一個新手。不要混淆一個新手,爲什麼*'它應該與'分開,爲什麼不''或'。請避免混淆的答案。 –

+0

我已經更新了答案@ un-lucky – Neel

+0

我還想補充一點,我們在考慮不要混淆新手,但在這種情況下,我們不應該低估他的問題。取而代之的是關閉它。 @聯合國幸運。只是一個想法。 – Neel