Concurrency violation on update command.
-
Hi all, I'm having a problem with updating a row in the table when the value was originally NULL. Using c# and Visual Studio 2005 by the way. Through my front end I can modify existing values and commit those changes to the database just fine, but the problem arises when I try and change a field that was NULL to a non-NULL value. (Oh, I can also change a field that has a value to NULL just fine) When I get to my DbAdapter.Update(DATASET HERE); line I catch an exception with the following text: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." And the thing is, when I comment out (of the update stored procedure in SQL) the part of the WHERE clause that states
((@IsNull_FIELDNAME = 1 AND [FIELDNAME] IS NULL) OR ([FIELDNAME] = @Original_FIELDNAME))
where FIELDNAME is the one field that I'm trying to update, it works fine. I can't figure out why that WHERE clause is failing. I'm not updating the database anywhere else in the code other than the one spot that is failing out when I try and fill a previously NULL field. I've used VS2005's auto-generating wizard to create my stored procedures and command generators so there isn't any disagreement between the table/SP/c# that I can find. When I breakpoint at the DbAdapter.Update(DATASET HERE); line my dataset has the right values in it. Does anyone have any ideas? I'm pretty stuck here. Thanks -
Hi all, I'm having a problem with updating a row in the table when the value was originally NULL. Using c# and Visual Studio 2005 by the way. Through my front end I can modify existing values and commit those changes to the database just fine, but the problem arises when I try and change a field that was NULL to a non-NULL value. (Oh, I can also change a field that has a value to NULL just fine) When I get to my DbAdapter.Update(DATASET HERE); line I catch an exception with the following text: "Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." And the thing is, when I comment out (of the update stored procedure in SQL) the part of the WHERE clause that states
((@IsNull_FIELDNAME = 1 AND [FIELDNAME] IS NULL) OR ([FIELDNAME] = @Original_FIELDNAME))
where FIELDNAME is the one field that I'm trying to update, it works fine. I can't figure out why that WHERE clause is failing. I'm not updating the database anywhere else in the code other than the one spot that is failing out when I try and fill a previously NULL field. I've used VS2005's auto-generating wizard to create my stored procedures and command generators so there isn't any disagreement between the table/SP/c# that I can find. When I breakpoint at the DbAdapter.Update(DATASET HERE); line my dataset has the right values in it. Does anyone have any ideas? I'm pretty stuck here. Thanksyou can using isnull fungtion to check on null isnull([FIELDNAME], @Original_FIELDNAME,FIELDNAME)