每當我試着通過SqlDataAdapter.Update()以單聲道更新行,我得到:單C#SQL更新 「併發衝突」
未處理的異常:System.Data.DBConcurrencyException:併發衝突: UpdateCommand影響了0條記錄。 在System.Data.Common.DbDataAdapter.Update(的System.Data.DataRow []數據行,SY stem.Data.Common.DataTableMapping tableMapping)[0x00000]
的相關C#代碼是:
IDbConnection conn = new SqlConnection(DB_CONN);
DataSet ds = new DataSet();
conn.Open();
IDbCommand command = conn.CreateCommand();
command.CommandText = "SELECT * FROM TestTable";
SqlDataAdapter adapter = new SqlDataAdapter((SqlCommand)command);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.Fill(ds);
ds.Tables[0].TableName = "TestTable";
ds.Tables[0].Rows[0]["testInt"] = 5;
adapter.Update(ds, "TestTable");
記錄查詢,因爲它擊中的SQL Server 2008後,它顯示:
exec sp_executesql N'UPDATE [TestUpdate] SET [id] = @p1, [testInt] = @p2 WHERE (([id] = @p3) AND ((@p4 = 1 AND [testInt] IS NULL) OR ([testInt] = @p5)))', N'@p1 int, @p2 int, @p3 int, @p4 int, @p5 int', @p1=1, @p2=5, @p3=1, @p4=NULL, @p5=NULL
數據庫是一個簡單的測試來調試這個問題上,兩列組成:一個整數id列(PK)和整數testInt列,允許有空值。該代碼工作正常,除非testInt值爲NULL,在這種情況下,該exeption被拋出。
UPDATE [TestUpdate]
SET [id] = 1,
[testInt] = 5
WHERE (([id] = 1)
AND ((NULL = 1 AND [testInt] IS NULL)
OR ([testInt] = NULL)))
看樣子@ P4應該是1在這種情況下,作爲應用IS NULL檢查,而不是爲NULL,這導致= NULL檢查(這我相信,如果值爲NULL會失敗)。
這是否看起來像一個單聲道的問題給其他人,還是我只是在做一些愚蠢/錯了嗎?
我已經提交了一個相關的錯誤https://bugzilla.novell.com/show_bug.cgi?id=522624 雖然原始的錯誤似乎對每個人都不是完全可重複的。鑑於此,我更希望是否有其他人遇到過它,或者知道解決方法。 – jxelam 2009-07-17 09:22:33