• Upgrade your Internet Experience
  • Sign in
  • Microsoft.com
  • United States (English)
    Brasil (Português)Česká republika (Čeština)Deutschland (Deutsch)España (Español)France (Français)Italia (Italiano)Россия (Русский)대한민국 (한국어)中华人民共和国 (中文)台灣 (中文)日本 (日本語)香港特别行政區 (中文)
 
 
Visual Basic Developer Center
 
 
Home
 
 
Library
 
 
Learn
 
 
Downloads
 
 
Support
 
 
Community
 
 
Forums
 
 
 
Visual Basic Developer Center > Visual Basic Forums > Visual Basic General > Saving TreeView Changes to Database
Ask a questionAsk a question
Search Forums:
  • Search Visual Basic General Forum Search Visual Basic General Forum
  • Search All Visual Basic Forums Search All Visual Basic Forums
  • Search All MSDN Forums Search All MSDN Forums
 

QuestionSaving TreeView Changes to Database

  • Saturday, July 15, 2006 4:01 PMSergio_CL Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    Hi all,

    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.

    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.

    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 ???

    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 ?

    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.

    Any other thoughts ?

    Thanks again,

    ST

     

    • ReplyReply
    • QuoteQuote
     

All Replies

  • Sunday, July 16, 2006 3:27 AMTimothy Ng MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Just 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.
    • ReplyReply
    • QuoteQuote
     
  • Wednesday, July 19, 2006 5:07 AMSergio_CL Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0

    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)?

    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 ?

    Thanks again,

    ST

    • ReplyReply
    • QuoteQuote
     
  • Friday, July 28, 2006 4:42 AMTimothy Ng MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    I 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.

    Were you able to implement the save feature by tracking the changes?
    • ReplyReply
    • QuoteQuote
     
  • Sunday, May 20, 2007 9:29 AMRamy Nagah Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Vote As Helpful
    0
    Do not forget to save the operations only after they have been completed successfully
    • ReplyReply
    • QuoteQuote
     
Need Help with Forums? (FAQ)
 
© 2009 Microsoft Corporation. All rights reserved.
Terms of Use
|
Trademarks
|
Privacy Statement