Home > Net >  Menu binding database to realize the secondary menu
Menu binding database to realize the secondary menu

Time:10-10

Consult everybody warrior, I am a novice, I want to make a menu bar with menu controls, binding database two tables, a root menu, one for the sub menu, treeview control did, but the menu error
The code For I=1 To DepartmentNum
DepartmentName=ds (I - 1). The Tables (" MyDepartment "). The Rows (I - 1). The Item (1). The ToString ()
Dim menunode As New MenuItem ()
Menunode. Text=DepartmentName (I - 1)
Menunode. Value=https://bbs.csdn.net/topics/DepartmentName (I - 1)
Menu1. Items. The Add (menunode)

DaTeam=New OleDbDataAdapter (" select * from Team='" Where sector & amp; DepartmentName (I - 1) & amp; "'", conn.)
DsTeam=New DataSet
DaTeam. The Fill (dsTeam, "MyTeam")
MyTeam TeamNum=dsTeam. Tables (" "). The Rows. Count
If TeamNum & gt; 0 Then
The Session (I & amp; "TeamNum")=TeamNum
ReDim TeamName (TeamNum - 1)
For j=1 To TeamNum
TeamName (j - 1)=dsTeam. Tables (" MyTeam "). The Rows (j - 1). The Item (1) the ToString

Dim menuchildnode As New MenuItem ()
Menuchildnode. Text=TeamName (j - 1)
Menuchildnode. Value=https://bbs.csdn.net/topics/TeamName (j - 1)
'Menu1. Items. The Add (menuchildnode)
Menu1. Items (0). ChildItems. Add (menuchildnode)
Next j
End the If
Next I
Run results

CodePudding user response:

To provide the required data XML content for debugging.

CodePudding user response:

You should use linq to SQL to achieve
LinqSQL class with these two tables, department, team
Dim dc new datacontext 'add your own data context
Dim qry1=the from r in dc. Department join dc. The team on dc. Department. DepartName like team. DepartName
The select r
Dim qryDpart=the from r in qry1
The select dName=distinct r.d epartName
For each r in qryDpart
Dim mnu1=new menuitem
Menu1. Text=r.d name
menu1.value=https://bbs.csdn.net/topics/r.dname
Dim childQry=the from r in qry1
The select r.t eamName where r.d epartname like menu1. Value
If childqry. Count> 0 then
For each r in childqry
Dim cMenu=new menuitem
Cmenu. Text=r.t eamName
cmenu.value=https://bbs.csdn.net/topics/r.teamName
Menu1. Items. The add (cmenu)
Next
End the if

Next

CodePudding user response:

Thank you all for the guidance!
  • Related