Help with Function...

G

Guest

Can someone please explain why this doesn't produce the required result?

It is suposed to pull some data from a database and build a some code similar to the line of code shown below:
Dim submenu1 As New skmMenu.MenuItem("Item Name", "URL")

...:: Code that doesn't work ::..
Private Function GetMenuDataSet(ByVal i_ParentID As Integer) As DataSet
'Returns a DataSet of MenuItems with a ParentID of what's passed in
Dim objConn As New SqlConnection("Data Source=server; Initial Catalog=Database; User ID=User; Password=****;")
Dim objAdapter As New SqlDataAdapter
Dim ds As New DataSet
objAdapter = New SqlDataAdapter("buildMenu " & i_ParentID, objConn)
ds = New DataSet
objAdapter.Fill(ds, "Menu")
Return ds
objAdapter.Dispose()
objConn.Close()
End Function

Private Sub DoMainMenuItems()
'This Subroutine handles the top level only
Dim dsMainItems As New DataSet
dsMainItems = GetMenuDataSet(0)
For Each dr As DataRow In dsMainItems.Tables(0).Rows
Dim MenuText As String = CstrNull(dr.Item("mnuName"))
Dim MenuMouseOver As String = CstrNull(dr.Item("mnuMouseOver"))
Dim MenuURL As String = CstrNull(dr.Item("mnuURL"))
Dim HasChildren As Boolean = (CLng0(dr.Item("Children")) > 0)
Dim MainItem As New skmMenu.MenuItem
MainItem.Text = MenuText
MainItem.ToolTip = MenuMouseOver
MainItem.Url = MenuURL
' If HasChildren Then
' DoSubMenuItems(MainItem, dr.Item("menuID"))
' End If
' Menu1.Items.Add(MainItem)
Next
 
K

Kevin Spencer

What does "build a some code" mean?

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Tim::.. said:
Can someone please explain why this doesn't produce the required result?

It is suposed to pull some data from a database and build a some code
similar to the line of code shown below:
Dim submenu1 As New skmMenu.MenuItem("Item Name", "URL")

..:: Code that doesn't work ::..
Private Function GetMenuDataSet(ByVal i_ParentID As Integer) As DataSet
'Returns a DataSet of MenuItems with a ParentID of what's passed in
Dim objConn As New SqlConnection("Data Source=server; Initial
Catalog=Database; User ID=User; Password=****;")
 
M

Marina

I see 2 problems:
1) You are not adding the MainItem object to the menu. You commented that
line out.
2) Your objAdapter.Dispose and objConn.Close statements are after the
return - so the never get executed. The good news, is that in the code you
have, you don't need either. The connection is opened and closed by the
Fill method, and the adapter doesn't need disposing. But it is strange to
have statements in your method that have no chance of being executed.

Tim::.. said:
Can someone please explain why this doesn't produce the required result?

It is suposed to pull some data from a database and build a some code
similar to the line of code shown below:
Dim submenu1 As New skmMenu.MenuItem("Item Name", "URL")

..:: Code that doesn't work ::..
Private Function GetMenuDataSet(ByVal i_ParentID As Integer) As DataSet
'Returns a DataSet of MenuItems with a ParentID of what's passed in
Dim objConn As New SqlConnection("Data Source=server; Initial
Catalog=Database; User ID=User; Password=****;")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top