المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : populate treeview from database



C# Programming
12-09-2009, 10:52 PM
I have found two ways to populate a treeview from a database. The first sets up a new class for each hierarchal level. Each class then contains a list of the associated child nodes. The database is queried once, then the records are dumped into the instances of the classes. This is the method used here:

Populating a TreeView Control from the Database (http://www.codeproject.com/KB/tree/TreeViewWithDatabase.aspx)[^ (http://www.codeproject.com/KB/tree/TreeViewWithDatabase.aspx)]

The second way I found of populating the treeview is to have a number of methods that query the database. Each query includes filters the data by the value of the parent node, such as here:

http://www.dotnetspider.com/resources/28676-Populate-TreeView-From-DataBase-Using-Recursive.aspx[^ (http://www.dotnetspider.com/resources/28676-Populate-TreeView-From-DataBase-Using-Recursive.aspx)]

My question is which way is preferable? I have a large about of data that I want work with, say, a hundred parent nodes that will drill down eight to ten hierarchal levels. It seems creating instances of a class for each record would use a lot of memory, but the second option has a lot of back-and-forth from the database. The data is coming from an oracle database, if that matters any.