Задайте вопросЗадайте вопрос
 

ВопросSaving TreeView Changes to Database

  • 15 июля 2006 г. 16:01Sergio_CL Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     

    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

     

Все ответы