Saving TreeView Changes to Database<p>Hi all,</p> <p>I have a treeview control in a VB.NET 2005 form that shows item category/subcategory, so root elements are all categories and child elements are all subcategories.   I pull the data off the database using code (no wizards), actually from two different tables.</p> <p>The user can add/change categories and subcategories.  No deletions are allowed, user can only mark them inactive.  To tie the categories to the subcategories I use a relationship between the two tables of the Access DB.  That all works perfect.</p> <p>My question is on how should I save the changes back to the two tables.  What would a good practice be ?  I thought I could delete both tables (categories and subcategories) and traverse the treeview to save record by record but I don't think this is the best method.  I'm not using automatic VS 2005 databinding, etc, this is pure code.  I could end up with two empty tables if the system crashes, etc.  Would this be a case for using a transaction ???</p> <p>Another thought would be to traverse the tree and perform an UPDATE command.  If 0 rows are affected, the item is new and therefore perform an INSERT...  Would this be acceptable in terms of performance ?</p> <p>I'm letting the user do all the maintenance on the treeview and once she's done I have a SAVE button.  I'm not saving every change she does on the fly.</p> <p>Any other thoughts ?</p> <p>Thanks again,</p> <p>ST</p> <p> </p>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z16891847-197f-49d1-9917-48aa0f5fe5eahttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#16891847-197f-49d1-9917-48aa0f5fe5eahttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#16891847-197f-49d1-9917-48aa0f5fe5eaSergio_CLhttp://social.msdn.microsoft.com/Profile/en-US/?user=Sergio_CLSaving TreeView Changes to Database<p>Hi all,</p> <p>I have a treeview control in a VB.NET 2005 form that shows item category/subcategory, so root elements are all categories and child elements are all subcategories.   I pull the data off the database using code (no wizards), actually from two different tables.</p> <p>The user can add/change categories and subcategories.  No deletions are allowed, user can only mark them inactive.  To tie the categories to the subcategories I use a relationship between the two tables of the Access DB.  That all works perfect.</p> <p>My question is on how should I save the changes back to the two tables.  What would a good practice be ?  I thought I could delete both tables (categories and subcategories) and traverse the treeview to save record by record but I don't think this is the best method.  I'm not using automatic VS 2005 databinding, etc, this is pure code.  I could end up with two empty tables if the system crashes, etc.  Would this be a case for using a transaction ???</p> <p>Another thought would be to traverse the tree and perform an UPDATE command.  If 0 rows are affected, the item is new and therefore perform an INSERT...  Would this be acceptable in terms of performance ?</p> <p>I'm letting the user do all the maintenance on the treeview and once she's done I have a SAVE button.  I'm not saving every change she does on the fly.</p> <p>Any other thoughts ?</p> <p>Thanks again,</p> <p>ST</p> <p> </p>Sat, 15 Jul 2006 16:01:21 Z2006-07-15T16:01:21Zhttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#d440d0f7-3f7b-47c7-8a68-7bb0669e0945http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#d440d0f7-3f7b-47c7-8a68-7bb0669e0945Timothy Ng MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Timothy%20Ng%20MSFTSaving TreeView Changes to DatabaseJust a thought - since you want to use the SAVE button, you could store a sequence of operations that the user does. You can even be smart here (say the user does an edit, then a delete - you can filter through your sequence of operations and remove extraneous operations). When the user hits save, you should use a transaction and translate your sequence of operations into the appropriate SQL statements.<br>Sun, 16 Jul 2006 03:27:59 Z2006-07-16T03:27:59Zhttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#1da9f92f-641a-44ff-8d7f-f28222020e6chttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#1da9f92f-641a-44ff-8d7f-f28222020e6cSergio_CLhttp://social.msdn.microsoft.com/Profile/en-US/?user=Sergio_CLSaving TreeView Changes to Database<p>Thanks Timothy for your reply.  Would you have a better way if I don't have the SAVE button to save all changes at once (at the end)?</p> <p>I could do with saving each change on the fly if that's a better practice.  If I go with this is there any code our there that shows how to do it ?</p> <p>Thanks again,</p> <p>ST</p>Wed, 19 Jul 2006 05:07:16 Z2006-07-19T05:07:16Zhttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#9f5562fc-3b33-4d34-bd6f-41b4325d5e5ahttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#9f5562fc-3b33-4d34-bd6f-41b4325d5e5aTimothy Ng MSFThttp://social.msdn.microsoft.com/Profile/en-US/?user=Timothy%20Ng%20MSFTSaving TreeView Changes to DatabaseI think it is better to use a save button, because from the user's perspective, it's more clear. The user can make changes, and the commit everything once they have double checked - that seems like a much better user model.<br><br>Were you able to implement the save feature by tracking the changes?<br>Fri, 28 Jul 2006 04:42:40 Z2006-07-28T04:42:40Zhttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#1df344ef-41bb-4243-b878-e04cda5f7bechttp://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/16891847-197f-49d1-9917-48aa0f5fe5ea#1df344ef-41bb-4243-b878-e04cda5f7becRamy Nagahhttp://social.msdn.microsoft.com/Profile/en-US/?user=Ramy%20NagahSaving TreeView Changes to DatabaseDo not forget to save the operations only after they have been completed successfullySun, 20 May 2007 09:29:43 Z2007-05-20T09:29:43Z