BobotheBugbear
02-16-2006, 11:36 AM
Creating a menu system from a DB that can have a submenu.
So, I figured I woudl just create to 2 sqldatareaders and have in inside the other . 1 the parent and the 2nd the child.
Dim objDataReader_parent As SqlDataReader
Dim objDataReader_child As SqlDataReader
And assign the child the parent values so they contain the same values since my stored procedure returns everything (main table linked with sub menu table by parent ID) (see attachment. this is the result of th query).
objDataReader_parent = objSqlCommand.ExecuteReader(Data.CommandBehavior.CloseConnection)
objDataReader_child = objDataReader_parent
Now when I generate the menus, they come out great except that I am missing some menu items in both the menu and submenus. First my count is off by 1 and then 2 and finally 3 where it stops (1 thing missing, then 2 missing and finally 3).
objDataReader_parent = objSqlCommand.ExecuteReader(Data.CommandBehavior.CloseConnection)
objDataReader_child = objDataReader_parent
Do While objDataReader_parent.Read()
Dim parentNode As New MenuItem
Dim parentID As Integer = objDataReader_parent.GetValue(0)
If IsDBNull(objDataReader_parent.GetValue(5)) Then
parentNode.NavigateUrl = objDataReader_parent.GetValue(2) & objDataReader_parent.GetValue(0)
parentNode.Text = objDataReader_parent.GetValue(1)
parentNode.Value = objDataReader_parent.GetValue(1)
mainMenu.Items.Add(parentNode)
End If
If Not IsDBNull(objDataReader_parent.GetValue(5)) Then
parentNode.NavigateUrl = objDataReader_parent.GetValue(2) & objDataReader_parent.GetValue(0)
parentNode.Text = objDataReader_parent.GetValue(1)
parentNode.Value = objDataReader_parent.GetValue(1)
mainMenu.Items.Add(parentNode)
Do While objDataReader_child.Read()
If Not IsDBNull(objDataReader_child.GetValue(5)) Then
If parentID = objDataReader_child.GetValue(5) Then
Dim childNode As New MenuItem
childNode.NavigateUrl = objDataReader_child.GetValue(7) & objDataReader_child.GetValue(4)
childNode.Text = objDataReader_child.GetValue(6)
childNode.Value = objDataReader_child.GetValue(6)
parentNode.ChildItems.Add(childNode)
Else
Exit Do
End If
End If
Loop
End If
Loop
Now, I'm thinking I won't be able to use a datareader for this specific purpose , yet it works so nice and is really fast. If there was a way for the parent node not to increment by 1 when going through the child node that would work. Anyone know of a way to force a datareader to only increment when you tell it to or have another idea?
Oh, this is 2.0 and I can't use the new stuff since the URL is the same, except for adding a different ID at the end or at least it didn't seem I could.
thanks
So, I figured I woudl just create to 2 sqldatareaders and have in inside the other . 1 the parent and the 2nd the child.
Dim objDataReader_parent As SqlDataReader
Dim objDataReader_child As SqlDataReader
And assign the child the parent values so they contain the same values since my stored procedure returns everything (main table linked with sub menu table by parent ID) (see attachment. this is the result of th query).
objDataReader_parent = objSqlCommand.ExecuteReader(Data.CommandBehavior.CloseConnection)
objDataReader_child = objDataReader_parent
Now when I generate the menus, they come out great except that I am missing some menu items in both the menu and submenus. First my count is off by 1 and then 2 and finally 3 where it stops (1 thing missing, then 2 missing and finally 3).
objDataReader_parent = objSqlCommand.ExecuteReader(Data.CommandBehavior.CloseConnection)
objDataReader_child = objDataReader_parent
Do While objDataReader_parent.Read()
Dim parentNode As New MenuItem
Dim parentID As Integer = objDataReader_parent.GetValue(0)
If IsDBNull(objDataReader_parent.GetValue(5)) Then
parentNode.NavigateUrl = objDataReader_parent.GetValue(2) & objDataReader_parent.GetValue(0)
parentNode.Text = objDataReader_parent.GetValue(1)
parentNode.Value = objDataReader_parent.GetValue(1)
mainMenu.Items.Add(parentNode)
End If
If Not IsDBNull(objDataReader_parent.GetValue(5)) Then
parentNode.NavigateUrl = objDataReader_parent.GetValue(2) & objDataReader_parent.GetValue(0)
parentNode.Text = objDataReader_parent.GetValue(1)
parentNode.Value = objDataReader_parent.GetValue(1)
mainMenu.Items.Add(parentNode)
Do While objDataReader_child.Read()
If Not IsDBNull(objDataReader_child.GetValue(5)) Then
If parentID = objDataReader_child.GetValue(5) Then
Dim childNode As New MenuItem
childNode.NavigateUrl = objDataReader_child.GetValue(7) & objDataReader_child.GetValue(4)
childNode.Text = objDataReader_child.GetValue(6)
childNode.Value = objDataReader_child.GetValue(6)
parentNode.ChildItems.Add(childNode)
Else
Exit Do
End If
End If
Loop
End If
Loop
Now, I'm thinking I won't be able to use a datareader for this specific purpose , yet it works so nice and is really fast. If there was a way for the parent node not to increment by 1 when going through the child node that would work. Anyone know of a way to force a datareader to only increment when you tell it to or have another idea?
Oh, this is 2.0 and I can't use the new stuff since the URL is the same, except for adding a different ID at the end or at least it didn't seem I could.
thanks