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