用深度遍历这颗数据库树
Function decomposeTree(fid,n)
dim strList
dim strIdList
dim zArr,zIdArr
if n>maxLeavel then Exit Function
strSQL="Select id,zitemid from work_bom where fitemid='" & fid & "'"
set rs=conn.Execute(strSQL) if not rs.eof then
strList=strList & rs("zitemid")
strIdList=strIdList & rs("id")
rs.movenext
while not rs.eof
strList=strList & "," & rs("zitemid")
strIdList=strIdList & "," & rs("id")
rs.movenext
wend
rs.close
set rs=nothing

zArr=split(strList,",")
zIdArr=split(strIdList,",")
for i=0 to UBound(zArr)
call AddItem(zIdArr(i),n+1)
call decomposeTree(zArr(i),n+1)
next
else
rs.close
set rs=nothing
end if
End Function