none
Cannot update fields in Linq table RRS feed

  • Question

  • I'm developing on Vista SP1 with VS 2008.  I'm also using Linq but have run into a problem with updates.

    Assuming that data entered passes the Validating event on the DataGridView and the user is ready to move on, the application is set up to flush the DGV to DB using Linq.  It is not the most elegant code right now because I've been trying everything I can think of to figure this one out.
    ======================================
    oRecord = New Disconnects
    myTN = CType(aTN(ndx), OneTN)    ' Array of Telephone info with changes

    With oRecord
         myStr = FormatTN(myTN.ReferTN, False) ' Formatted Telephone
         .TN_Referral = myStr     ' <-- Different values but no change
         .Term = myTN.Term      ' Same here
    End With
    ==============================

    The code fails while trying to update oRecord.  Debugging reveals changed value for TN_Referral and Term but the oRecord values to not change.  I traced this into the generated code to this instruction in the TN_Referral property in DB.Designer.vb:

    If (String.Equals(Me._TN_Referral, value) = false) Then

    Both _TN_Referral and value have the same values here even though oRecord.TN_Referral and myStr have different values.  Therefore, the set instructions are completely skipped. 

    I need help with this.  Any ideas?


    ebassador
    "Find it, fix it, move on."
    Tuesday, March 16, 2010 11:48 PM

All replies

  • Sorry to ask a silly question, but I don't understand what you mean by "Debugging reveals changed value for TN_Referral and Term but the oRecord values do not change".

    You say that both _TN_Referral and value have the same values in the String.Equals check. Which one is the right value and which is wrong?


    Wednesday, March 17, 2010 12:54 PM
  • Sorry John. 

    In the code I wrote, oRecord.TN_Referral has the original value and myStr has the changed value.  I've confirmed this in the debugger by setting a breakpoint and viewing the variable values prior to executing the instruction on the line ".TN_Referral = myStr". 

    Next, I stepped into the code of DB.Designer.vb which is generated by Linq.  In the generated code the value of _TN_Referral is the same as the value being passed to the property set commands. 

    I can't understand why TN_Referral and _TN_Referral do not have the same value at this point.
    ebassador
    "Find it, fix it, move on."
    Wednesday, March 17, 2010 1:24 PM
  • Goodness me, that is strange! So, if I understand correctly then you have something like this

    Before
    oRecord.TN_Referral is 'original value'.
    myStr is 'new value'.

    In the property set code,
    value is 'new value'.
    _TN_Referral is also 'new value' ... even though it should still be 'original value'.

    Afterwards
    oRecord.TN_Referral is still 'original value' (is it?).

    I'm afraid I can't suggest why that would be.

    I'm sure you've tried these, but it might be worth me saying out loud. Have you set a breakpoint in the property set to see if it is being called a second time? What happens if you do a Refresh on the object before trying to update it? What happens if you update it with a string literal in isolation of the rest of the commands (e.g. oRecord.TN_Referral = "Test")?

    Beyond this, I don't think I'll be able to help more.
    Wednesday, March 17, 2010 2:09 PM
  • Hello,

    I agree that it is really strange.  I would suggest you follow John's debugging method and try to provide us with more detailed information please. 

    Have a nice day, both!


    Best Regards,
    Lingzhi Sun


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, March 22, 2010 4:30 PM
    Moderator