Wrong value on update

Last post 07-01-2009 8:36 AM by sjnaughton. 4 replies.

Sort Posts:

  • Wrong value on update

    07-01-2009, 5:53 AM
    • Member
      1 point Member
    • michaelr524
    • Member since 03-07-2007, 6:24 PM
    • Posts 20

    Hey people,

    Here is a strange problem. I've created a DD Linq2Sql website.

    When editing and then updating a row one of the foreign fields is wrong on update

    and causes an error in SQL. I don't understand where does it take it's value from.

    The value which is sent through AJAX from the select box is right, but when I put a break point in the update method I could see the value is wrong there.

        partial void UpdateReadiness_ActivitiesHistory(Readiness_ActivitiesHistory instance)

        {

    // here I set the breakpoint and inspected 'instance'

            ExecuteDynamicUpdate(instance);

        }


    Has anyone had any experience of this kind?
    Please help.

    Thanks
    Michael

        partial void UpdateReadiness_ActivitiesHistory(Readiness_ActivitiesHistory instance)
        {
            ExecuteDynamicUpdate(instance);
        }


  • Re: Wrong value on update

    07-01-2009, 6:33 AM
    • Participant
      1,066 point Participant
    • stevew1975
    • Member since 05-29-2009, 2:51 PM
    • Bristol, UK
    • Posts 189

    Check you page load, are you updating it with the original value here.  If so you may need the !IsPostback check.




    Please mark this post as answered if it helped you!
  • Re: Wrong value on update

    07-01-2009, 7:00 AM
    • Member
      1 point Member
    • michaelr524
    • Member since 03-07-2007, 6:24 PM
    • Posts 20

    Hey Steve,


    Can you explain please, I didn't really understand your answer.

    The original value is loaded automaticly then I edit a row and then I update and get this:

    Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The UPDATE statement conflicted with the FOREIGN KEY constraint "FK_Readiness_ActivitiesHistory_Readiness_ActivitiyStatusFactorDef". The conflict occurred in database "ReportsEden", table "dbo.Readiness_ActivitiyStatusFactorDef".
    The statement has been terminated.

    Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: The UPDATE statement conflicted with the FOREIGN KEY constraint 

    I inspected the values sent from the page using FireBug and then I inspected the values before they are being sent to the database and they are not the same.


    Thanks

    Michael

  • Re: Wrong value on update

    07-01-2009, 7:38 AM
    • Participant
      1,066 point Participant
    • stevew1975
    • Member since 05-29-2009, 2:51 PM
    • Bristol, UK
    • Posts 189

    What happens when you do an update or anything that posts back, is that the page_load is run before your update code.

    I was just checking to see if there is anything in your page_load which is updating the information before hitting your update code.




    Please mark this post as answered if it helped you!
  • Re: Wrong value on update

    07-01-2009, 8:36 AM
    • Star
      12,086 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,532
    • TrustedFriends-MVPs

     If it's a ForiegnKey field I would check the ExtractValue method of the ForeignKey_Edit.aspx.cs and see what value it has when you put a break point in there.

    You can a a break point with a condition i.e. Column.Name == "MyColumn" and then it will only breal on that column if you have several in that table.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
Page 1 of 1 (5 items)