Unable to update a field that has a NULL valuehttp://forums.asp.net/t/1772196.aspx/1?Unable+to+update+a+field+that+has+a+NULL+valueWed, 29 Feb 2012 20:30:22 -050017721964843757http://forums.asp.net/p/1772196/4843757.aspx/1?Unable+to+update+a+field+that+has+a+NULL+valueUnable to update a field that has a NULL value <p>I'm unable to update a field from page 1 if the starting value is NULL.&nbsp; Once the value has been set, by a different page, then I can go back to page 1 and update that field.</p> <p>I know just above zero about SQL.&nbsp;</p> <p>My update string, generated by Visual Web Studio is:</p> <p>UpdateCommand=&quot;UPDATE [WaferTrack2] SET [Location] = @Location, [Slot] = @Slot, [Customer] = @Customer, [Fab] = @Fab, [Layer] = @Layer, [DR] = @DR, [Size] = @Size, [Notes] = @Notes, [Returned] = @Returned, [DateTimeStamp] = @DateTimeStamp, [Type] = @Type, [Owner] = @Owner, [AppsEng] = @AppsEng WHERE [ID] = @original_ID AND [Location] = @original_Location AND [Slot] = @original_Slot AND [Customer] = @original_Customer AND (([Fab] = @original_Fab) OR ([Fab] IS NULL AND @original_Fab IS NULL)) AND [Layer] = @original_Layer AND (([DR] = @original_DR) OR ([DR] IS NULL AND @original_DR IS NULL)) AND [Size] = @original_Size AND (([Notes] = @original_Notes) OR ([Notes] IS NULL AND @original_Notes IS NULL)) AND [Returned] = @original_Returned AND (([DateTimeStamp] = @original_DateTimeStamp) OR ([DateTimeStamp] IS NULL AND @original_DateTimeStamp IS NULL)) AND (([Type] = @original_Type) OR ([Type] IS NULL AND @original_Type IS NULL)) AND (([Owner] = @original_Owner) OR ([Owner] IS NULL AND @original_Owner IS NULL)) AND (([AppsEng] = @original_AppsEng) OR ([AppsEng] IS NULL AND @original_AppsEng IS NULL))&quot;</p> <p>Any ideas what I'm missing?&nbsp; </p> <p>Thanks</p> 2012-02-21T19:32:52-05:004843775http://forums.asp.net/p/1772196/4843775.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p>The code is correct, please check the parameters values before the update, make sure that the parameters carrying the original values are null</p> 2012-02-21T19:48:27-05:004843890http://forums.asp.net/p/1772196/4843890.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p>Thanks for the reply.&nbsp; I've verified that the value in the table itself is NULL by going direclty to the table, but I don't know how to check the parameter and see its value.&nbsp; There is no code behind the page to set a breakpoint so I'm at a loss here.</p> <p></p> <p>Thanks</p> 2012-02-21T21:32:19-05:004843898http://forums.asp.net/p/1772196/4843898.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Lupin-III</h4> <p></p> <p>I'm unable to update a field from page 1 if the starting value is NULL.&nbsp; Once the value has been set, by a different page, then I can go back to page 1 and update that field.</p> <p>I know just above zero about SQL.&nbsp;</p> <p>My update string, generated by Visual Web Studio is:</p> <p>UpdateCommand=&quot;UPDATE [WaferTrack2] SET [Location] = @Location, [Slot] = @Slot, [Customer] = @Customer, [Fab] = @Fab, [Layer] = @Layer, [DR] = @DR, [Size] = @Size, [Notes] = @Notes, [Returned] = @Returned, [DateTimeStamp] = @DateTimeStamp, [Type] = @Type, [Owner] = @Owner, [AppsEng] = @AppsEng WHERE [ID] = @original_ID AND [Location] = @original_Location AND [Slot] = @original_Slot AND [Customer] = @original_Customer AND (([Fab] = @original_Fab) OR ([Fab] IS NULL AND @original_Fab IS NULL)) AND [Layer] = @original_Layer AND (([DR] = @original_DR) OR ([DR] IS NULL AND @original_DR IS NULL)) AND [Size] = @original_Size AND (([Notes] = @original_Notes) OR ([Notes] IS NULL AND @original_Notes IS NULL)) AND [Returned] = @original_Returned AND (([DateTimeStamp] = @original_DateTimeStamp) OR ([DateTimeStamp] IS NULL AND @original_DateTimeStamp IS NULL)) AND (([Type] = @original_Type) OR ([Type] IS NULL AND @original_Type IS NULL)) AND (([Owner] = @original_Owner) OR ([Owner] IS NULL AND @original_Owner IS NULL)) AND (([AppsEng] = @original_AppsEng) OR ([AppsEng] IS NULL AND @original_AppsEng IS NULL))&quot;</p> <p>Any ideas what I'm missing?&nbsp;</p> <p>Thanks</p> <p></p> </blockquote> <p></p> <p>First, I've heard good things about the book, Teach Yourself SQL in 10 Minutes by Ben Forta.</p> <p>Now, about this machine generated code, let's try to make it easier to read.</p> <p></p> <p>WHERE [ID] = @original_ID</p> <p>AND [Location] = @original_Location</p> <p>AND [Slot] = @original_Slot</p> <p>AND [Customer] = @original_Customer</p> <p>AND (([Fab] = @original_Fab) OR ([Fab] IS NULL AND @original_Fab IS NULL))</p> <p>AND [Layer] = @original_Layer</p> <p>AND (([DR] = @original_DR) OR ([DR] IS NULL AND @original_DR IS NULL)) AND [Size] = @original_Size AND (([Notes] = @original_Notes) OR ([Notes] IS NULL AND @original_Notes IS NULL))</p> <p>AND [Returned] = @original_Returned</p> <p>AND (([DateTimeStamp] = @original_DateTimeStamp) OR ([DateTimeStamp] IS NULL AND @original_DateTimeStamp IS NULL))</p> <p>AND (([Type] = @original_Type) OR ([Type] IS NULL AND @original_Type IS NULL))</p> <p>AND (([Owner] = @original_Owner) OR ([Owner] IS NULL AND @original_Owner IS NULL))</p> <p>AND (([AppsEng] = @original_AppsEng) OR ([AppsEng] IS NULL AND @original_AppsEng IS NULL))&quot;</p> <p>You state that you are unable to update a field if the starting value is null.&nbsp; To which field do you refer?</p> 2012-02-21T21:41:11-05:004846049http://forums.asp.net/p/1772196/4846049.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p>Three suggestions for you &nbsp;Lupin-III</p> <p>1In your aspx pagethere should be something like UpdateParametersplease set DefaultValue=&quot;&quot; for all the stringsand set ConvertEmptyStringToNull=True</p> <p>2Check whether you've set DataKeyNames for GridViewor DataKeys for other controls like Repeater or something else</p> <p>3Converting the Update to TemplateFieldand then handle GridView_RowUpdatingplz use something like e.Command,e.Parameters to debug to see what's happening</p> <p>Reguards</p> 2012-02-23T00:42:06-05:004847480http://forums.asp.net/p/1772196/4847480.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p>Dan - Thanks for helping on this.&nbsp; <span style="text-decoration:line-through"> The AppsEng field is the one giving me trouble</span>.&nbsp; It was added to the table after release.&nbsp;</p> <p>Edit: Apparently any field that does not have data already is not saving the update.</p> 2012-02-23T14:18:41-05:004847484http://forums.asp.net/p/1772196/4847484.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p>Decker - Thanks for the suggestions.&nbsp; I'll take a look at this.</p> <p></p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Decker Dong - MSFT</h4> <p></p> <p>Three suggestions for you &nbsp;Lupin-III</p> <p>1In your aspx pagethere should be something like UpdateParametersplease set DefaultValue=&quot;&quot; for all the stringsand set ConvertEmptyStringToNull=True</p> <p>2Check whether you've set DataKeyNames for GridViewor DataKeys for other controls like Repeater or something else</p> <p>3Converting the Update to TemplateFieldand then handle GridView_RowUpdatingplz use something like e.Command,e.Parameters to debug to see what's happening</p> <p>Reguards</p> <p></p> </blockquote> <p></p> 2012-02-23T14:19:52-05:004848185http://forums.asp.net/p/1772196/4848185.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p>Hello again</p> <p>Welcome your feedback again</p> 2012-02-23T23:56:58-05:004848259http://forums.asp.net/p/1772196/4848259.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Dan Bracuk</h4> <p></p> <p>Now, about this machine generated code, let's try to make it easier to read.</p> <p>WHERE [ID] = @original_ID</p> <p>AND [Location] = @original_Location</p> <p>AND [Slot] = @original_Slot</p> <p>AND [Customer] = @original_Customer</p> <p>AND (([Fab] = @original_Fab) OR ([Fab] IS NULL AND @original_Fab IS NULL))</p> <p>AND [Layer] = @original_Layer</p> <p>AND (([DR] = @original_DR) OR ([DR] IS NULL AND @original_DR IS NULL))</p> <p>AND [Size] = @original_Size AND (([Notes] = @original_Notes) OR ([Notes] IS NULL AND @original_Notes IS NULL))</p> <p>AND [Returned] = @original_Returned</p> <p>AND (([DateTimeStamp] = @original_DateTimeStamp) OR ([DateTimeStamp] IS NULL AND @original_DateTimeStamp IS NULL))</p> <p>AND (([Type] = @original_Type) OR ([Type] IS NULL AND @original_Type IS NULL))</p> <p>AND (([Owner] = @original_Owner) OR ([Owner] IS NULL AND @original_Owner IS NULL))</p> <p>AND (([AppsEng] = @original_AppsEng) OR ([AppsEng] IS NULL AND @original_AppsEng IS NULL))&quot;</p> <p></p> </blockquote> <p></p> <p>What is the primary key of the table?&nbsp; If it's ID, once you have this:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE [ID] = @original_ID</p> <p>why is the rest of that stuff in your where clause?</p> 2012-02-24T01:48:27-05:004857506http://forums.asp.net/p/1772196/4857506.aspx/1?Re+Unable+to+update+a+field+that+has+a+NULL+valueRe: Unable to update a field that has a NULL value <p></p> <blockquote><span class="icon-blockquote"></span> <h4>Dan Bracuk</h4> <p></p> <p>What is the primary key of the table?&nbsp; If it's ID, once you have this:</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHERE [ID] = @original_ID</p> <p>why is the rest of that stuff in your where clause?</p> <p></p> </blockquote> <p></p> <p></p> <p>ID is the primary key and I don't know why all the extra stuff, as I said, i'm an SQL noob.</p> <p>I removed the &quot;stuff&quot; and it works now.</p> <p>Thanks</p> 2012-02-29T20:30:22-05:00