2013-05-10 25 views
2

我試着從我的數據庫中刪除一行,爲什麼asp.net不會刪除我的行?

這是我的代碼:

sql = "delete sum_lines from sum_lines join sum_tbl on sum_lines.summary_id = sum_tbl.id where sum_tbl.user_id = @userId and sum_lines.line_id ='@lineId'"; 

     SqlConnection con = new SqlConnection(conString); 
     dataObj = new DataObj(); 
     SqlCommand com = new SqlCommand(sql, con); 
     com.Parameters.Add(new SqlParameter("@userId", userId)); 
     com.Parameters.Add(new SqlParameter("@lineId", lineId)); 


     con.Open(); 
     com.ExecuteNonQuery(); 
     con.Close(); 

的事情是,如果我試着在管理工具中我的SQL語句,它完美的作品。 但是當我的代碼運行時,它不會影響我的數據庫。

它是否會轉到此代碼,我可以在我的調試模式下看到,但由於某種原因它不會生效。 任何輸入?

+0

你在用'TransactionScope'嗎? – Sachin 2013-05-10 01:42:33

+0

我不知道它是什麼,所以我猜不是 – thormayer 2013-05-10 01:43:35

+0

你能告訴我們一個連接字符串的消毒版本嗎? – IrishChieftain 2013-05-10 01:45:23

回答

6

刪除單引號約'@lineId'。用引號指定第二個條件中的值等於@lineid的字符串。

+0

哦謝謝,它的工作。我以爲因爲它是一個字符串,你必須放置單個qoutes。不要猜測它是否在參數中。你已經幫了你。謝謝。 – thormayer 2013-05-10 01:46:14

+2

@thormayer - 將sql語句中的參數視爲變量。使用'com.Parameters.Add'指定這些變量的值。 – Igor 2013-05-10 01:48:33

相關問題