The problem is that I want the tree view to be built from a dataset or datareader...or whatever that is fast...there will be about 300 categories. and I don't want to have 300 database calls to build the table...

I thought about a stored procedure...but I don't really know how I would go about to implement that....Also I thought about maybe a 3 level nested loop....but that would involved making a database call every time...(Which is obviously not a good idea) I also thought about the nested loop but instead of many database calls...I can make one database call. get all the categories...then store it in a dataset or datareader ( I think datareader would be faster, not sure if I can have realtionships in a datareader though....) and then read it and populate my Tree view..

This is what I have so far... Stored procedure under it....which is really not that advanced...

1) Drop OwnerId and SubOwnerId , Create a column called ParentCategoryId, Now the table could support more than 3 level of hierarchy.
2) Here is a sample query to retrieve the data in tree view order
------------------------------------------------------------------------
with result(catid,categoryname,level,orderby)
as
(
select catid,categoryname,3,row_number() over (order by catid) * Power(10,3 * 2)
from categories
where parentid = 0
union all
select c.catid,c.categoryname,r.level - 1,r.orderby + row_number() over (order by c.catid) * Power(10,(level - 1) * 2)
from categories c inner join result r on c.parentid = r.catid
)
select * from result order by orderby
--------------------------------------------------------------------------
The query is hard coded to support 3 level in
select catid,categoryname,3,row_number() over (order by catid) * Power(10,3 * 2) (you can change the number if you want)
The query is hard coded to support every category can only have 99 immediate subcategories.
Power(10,(level - 1) * 2) (if you can the 2 to 3 then it could support 999)
The max for t-sql is Power(10,9), so it's not support many levels. If you want to support more levels, use a varchar type for ordering.

your example worked..now I need to link it to my table in the database...another thing you might not of noticed..but the table is language independant...if I would want the category names in french for instance...would I just add... where langaugeID='Fre' at the end of your select?

Also wondering what is the purpose of the ParentCategoryId field.

and what does it's contents mean? since I'm going to be filling the database from a form I need to know how to properly insert the data.

The query I put here is just for example.
You have to modify it according to your needs.
It does not select all columns and the orderby column does not need to be selected.
ParentCategoryId is the CatId of the row which is the parent of current row.
Use one parent idcolumn just to simplify the query. Your table structure could also be used as long as you can come up a query which returns the result in the right order.

1) You don't need the generic dictionary in the code. You can loop through the data reader.
2) Unless you set the order statically in the table, you have to have the orderby column to get the right result.
The following might work for you:
ALTER PROCEDURE [dbo].[usp_GetCategories]
@langID char(3)
AS
with result(CategoryID,CategoryName,level,OrderBy)
as
(
select CategoryID,CategoryName,3,row_number() over (order by CategoryName ) * Power(10,3 * 2)
from Categories
where ParentCategoyID = 0 and LanguageID=@langID
union all
select c.CategoryID,c.CategoryName,r.level - 1,r.OrderBy + row_number() over (order by c.CategoryName) * Power(10,(level - 1) * 2)
from Categories c inner join result r on c.ParentCategoyID = r.CategoryID where LanguageID=@langID
)
select CategoryName,level from result order by OrderBy

An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: An item with the same key has already been added.

Featured Post

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

ASP.Net to Oracle Connectivity
Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers to develop an ASP.NET client…

Problem
Hi all,
While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.
If your ASP.NET page …

This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg).
If you're looking for how to monitor bandwidth using netflow or packet s…

This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory.
NOTE: For Outlook 2016 and 2013 perform the exact same steps.
Open a new email: Click the New email button in Outlook.
Start typing the address: …