Results 1 to 13 of 13

Thread: [RESOLVED] "Row cannot be located for updating" - when updating db recursively

  1. #1

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Resolved [RESOLVED] "Row cannot be located for updating" - when updating db recursively

    In the following code I'm recursively saving current vieworder of a Treeview's nodes to a Access2000 db. I'm using ADO 2.8. (The original code was for saving treeview vieworder in a text file. I found it somewhere on the web)

    At first I was getting an error,
    -2147217864 : Row cannot be located for updating. Some values may have been changed since it was last read.

    I tried using .Requery, Close-Reopen, .Update, but nothing worked. Then finally the .Resync method worked. I'm not sure why it worked !

    My problem is, this Requery process is painfully slow. Every time user adds a node and the treeview has, say, >10 nodes, it is taking 10-20 seconds ! Every time user adds/deletes/sorts/drags node, I have to update their viewing index in db.

    I don't have very much experience in database programming. (My instinct says it may have something to do with recursion and stack.)

    1. Can anyone please tell me why that Resync method works and why everything else fails even if I perform a CommitTrans ?

    2. Can anyone plese help me make this code faster.

    Thanks !

    VB Code:
    1. Friend Sub ParseTree(objNode As Node)
    2.  
    3.     ' Recursively updates TreeIndex field in DB according to the node's level
    4.    
    5.     '----------------------------------------
    6.     ' Update DB
    7.     rs.MoveFirst
    8.     cnn.BeginTrans
    9.     ' The Treeview Keys are  "_N21" or similar
    10.     rs.Find "ID = " & Right$(objNode.Key, Len(objNode.Key) - 2)
    11.     rs!TreeIndex = ViewIndex 'ViewIndex is a global var to track current node
    12.     '                         placement in the treeview
    13.    
    14.     '[b]ToDo: This Resync process takes too much time.
    15.     ' If I comment this:
    16.     '[color=red] ERROR -2147217864 : Row cannot be located for updating. _[/color]
    17.      '[color=red] Some values may have been changed since it was last read.[/color]
    18.     rs.Resync [/b]
    19.    
    20.     cnn.CommitTrans
    21.     '----------------------------------------
    22.    
    23.     ViewIndex = ViewIndex + 1
    24.    
    25.     ' Check to see if the current node has children
    26.     If objNode.Children > 0 Then
    27.         ' Pass the first child node to the print routine
    28.         ParseTree objNode.Child
    29.     End If
    30.  
    31.     ' Set the next node to print
    32.     Set objNode = objNode.Next
    33.     ' As long as we have not reached the last node in
    34.     ' a branch, continue to call the print routine
    35.  
    36.     If TypeName(objNode) <> "Nothing" Then
    37.         ParseTree objNode
    38.     End If
    39.  
    40. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: "Row cannot be located for updating" - when updating db recursively

    1). You should be using .Update followed by CommitTrans.

    If you are getting errors with the .Update, let us know (I don't use .Find myself, so that may cause issues).

  3. #3

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: "Row cannot be located for updating" - when updating db recursively

    Yes I'm having problem with Update. That's why I used Resync.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: "Row cannot be located for updating" - when updating db recursively

    what problem(s) are you having with update? Is it the error you posted?

  5. #5

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: "Row cannot be located for updating" - when updating db recursively

    Yes. It is the same error.

    -2147217864 : Row cannot be located for updating. Some values may have been changed since it was last read.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: "Row cannot be located for updating" - when updating db recursively

    ONLY resync works. But it is too slow.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: "Row cannot be located for updating" - when updating db recursively

    Well there's two possible issues I can think of, the first is that .Find is doing something to cause it (you could try updating the first record without it to see if that works).

    The second thing I can think of is that you do not have a unique identifier for the row, so when you update a row which is similar to another, this error is shown to stop a possible update to the wrong row.

  8. #8

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: "Row cannot be located for updating" - when updating db recursively

    Quote Originally Posted by si_the_geek
    Well there's two possible issues I can think of, the first is that .Find is doing something to cause it (you could try updating the first record without it to see if that works).
    Thanks. I'll try it.
    Quote Originally Posted by si_the_geek
    The second thing I can think of is that you do not have a unique identifier for the row, so when you update a row which is similar to another, this error is shown to stop a possible update to the wrong row.
    Sorry I don't understand it. I have primary keys in the db (autonumber).

    Here is my query:
    VB Code:
    1. With rs
    2.         .ActiveConnection = cnn
    3.         .LockType = adLockOptimistic
    4.         .Open "SELECT * FROM tblNotes ORDER BY IsNote DESC,[TreeIndex]"
    5.     End With
    And here are the fields:
    Attached Images Attached Images  
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: "Row cannot be located for updating" - when updating db recursively

    In that case you are ok for that - primary keys are (by definition) unique identifiers.

  10. #10

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: "Row cannot be located for updating" - when updating db recursively

    Omitting Find did the trick. Thanks !

    ( I'm still confused about why Find was causing the problem. A bug in ADO maybe ?)
    VB Code:
    1. Friend Sub ParseTree(objNode As Node)
    2.  
    3.     ' Recurstmpively updates TreeIndex field in DB according to the node's level
    4.     Dim rsTmp As ADODB.Recordset
    5.     Set rsTmp = New ADODB.Recordset
    6.    
    7.     '----------------------------------------
    8.     ' Update DB
    9.     With rsTmp
    10.         .ActiveConnection = cnn
    11.         .LockType = adLockOptimistic
    12.         .Open "SELECT * FROM tblNotes WHERE ID = " _
    13.            & Right$(objNode.Key, Len(objNode.Key) - 2) & _
    14.            " ORDER BY IsNote DESC,[TreeIndex]"
    15.     End With
    16.  
    17.     If rsTmp.RecordCount = 1 Then
    18.         rsTmp.MoveFirst
    19.         cnn.BeginTrans
    20.         ' The Treeview Keys are  "_N21" or similar
    21.         rsTmp!TreeIndex = ViewIndex 'ViewIndex is a global var to track current node
    22.         '                         placement in the treeview
    23.         rsTmp.Update
    24.         cnn.CommitTrans
    25.         rsTmp.Close
    26.     ElseIf rsTmp.RecordCount > 1 Then
    27.         MsgBox "Database Error ! More than one primary keys !!!!", vbCritical
    28.         Exit Sub
    29.     Else
    30.         MsgBox "Database Error ! Can't find the node in datbase primary keys !", vbCritical
    31.         Exit Sub
    32.     End If
    33.  
    34.     '----------------------------------------
    35.    
    36.     ViewIndex = ViewIndex + 1
    37.    
    38.     ' Check to see if the current node has children
    39.  
    40.     If objNode.Children > 0 Then
    41.         ' Pass the firstmpt child node to the print routine
    42.         ParseTree objNode.Child
    43.     End If
    44.  
    45.     ' Set the next node to print
    46.     Set objNode = objNode.Next
    47.     Set rsTmp = Nothing
    48.  
    49.     ' As long as we have not reached the last node in
    50.     ' a branch, continue to call the print routine
    51.     If TypeName(objNode) <> "Nothing" Then
    52.         ParseTree objNode
    53.     End If
    54.  
    55. End Sub
    Last edited by iPrank; Jan 9th, 2006 at 03:06 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] "Row cannot be located for updating" - when updating db recursively

    Good stuff Could you mark the thread as resolved please? (on the Thread Tools menu above)

    My guess is that the standard behaviour of Find invalidates the recordset, as it filters it (and as such effectively creates a new recordset).

  12. #12

    Thread Starter
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: [RESOLVED] "Row cannot be located for updating" - when updating db recursively

    Quote Originally Posted by si_the_geek
    Good stuff Could you mark the thread as resolved please? (on the Thread Tools menu above)
    Sorry. I was busy testing the code.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  13. #13
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: [RESOLVED] "Row cannot be located for updating" - when updating db recursively

    Have you tried interchanging the positions of your code like the ff...?

    VB Code:
    1. rs.Find "ID = " & Right$(objNode.Key, Len(objNode.Key) - 2)
    2. cnn.BeginTrans
    3. rs!TreeIndex = ViewIndex
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width