Thursday, 15 April 2010

asp.net - Populate a multidimensional array (recursive relationship) from query -



asp.net - Populate a multidimensional array (recursive relationship) from query -

i'm trying populate multidimensional array back upwards next recursive relationship (the info coming database table).

this multidimensional array used generate list below. have minimal experience multidimensional arrays in vb.net. help appreciated. if think there's improve way accomplish this, allow me know.

data

id name parentid 10 bobby brownish 50 20 dave matthew 80 30 sergey boostad 50 40 linda view 50 50 bill lumberg 60 rina gina 50 70 ben thompson 100 80 maria tree 50 90 gustav duffield 80 100 jon theodore 110 cedric loomis 100 120 jeremy oscar 100

output (to achieve)

[50] - bill lumberg [10] - bobby brownish [30] - sergey boostad [40] - linda view [60] - rina gina [80] - maria tree [20] - dave matthew [90] - gustav duffield [100] - jon theodore [70] - ben thompson [110] - cedric loomis [120] - jeremy oscar

to store tree in memory, can create class this:

public class namenode public sub new(name string) me.name = name end sub public property name string public level integer public property children new list(of namenode) end class

then, can utilize this:

dim bill new namenode("bill lumberg") bill.children.add(new namenode("bobby brown") bill.children.add(new namenode("sergey boostad")

to fill flat dataset, you'd need create recursive method, instance:

public function buildnode(data dataset, nameid integer, level integer), namenode dim node new namenode() node.level = level ' find name id in dataset , set node's name property accordingly dim childids new list(of integer) ' search list of name id's have current id parent each integer in childids node.children.add(buildnode(data, i, level + 1)) next homecoming node end function

then build whole bill lumberg branch calling this:

dim bill namenode = buildnode(data, 50, 0)

asp.net arrays vb.net multidimensional-array

No comments:

Post a Comment