Re: WHY, WHY WON'T IT WORK???

Discussion in 'ASP .Net' started by Marina, Jun 29, 2004.

  1. Marina

    Marina Guest

    Your GetMenuDataSet function, never actually returns the dataset. It creates
    it, fills it with data - but never actually returns the object.

    I would have expected your code to fail where you go to
    dsMainItems.Tables(0).Rows, since there were no tables, because dsMainItems
    is always just an empty dataset.

    Also, to find out what is going in, you can just debug into the code, go
    through it line by line to see what the issue is.

    "Tim::.." <myatix_at_hotmail.com> wrote in message
    news:...
    > Has anyone got any idea why this piece of code doesn't work? For some

    reason I just can't get this piece of code work!
    >
    > I don't get any errors it just doesn't do anything???? It is ment to build

    a menu from a database!
    >
    >
    > Imports System.Data
    > Imports System.Data.SqlClient
    > Public Class Webdefault
    > Inherits System.Web.UI.Page
    >
    > #Region " Web Form Designer Generated Code "
    >
    > 'This call is required by the Web Form Designer.
    > <System.diagnostics.debuggerstepthrough()> Private Sub

    InitializeComponent()
    >
    > End Sub
    > Protected WithEvents Menu1 As skmMenu.Menu
    >
    > 'NOTE: The following placeholder declaration is required by the Web

    Form Designer.
    > 'Do not delete or move it.
    > Private designerPlaceholderDeclaration As System.Object
    >
    > Private Sub Page_Init(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MyBase.Init
    > 'CODEGEN: This method call is required by the Web Form Designer
    > 'Do not modify it using the code editor.
    > InitializeComponent()
    > End Sub
    >
    > #End Region
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As

    System.EventArgs) Handles MyBase.Load
    >
    > If Not Page.IsPostBack Then
    > DoMainMenuItems()
    > End If
    > End Sub
    >
    > 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.ToolTip = MenuText
    > MainItem.ToolTip = MenuMouseOver
    > MainItem.Url = MenuURL
    > If HasChildren Then DoSubMenuItems(MainItem,

    dr.Item("menuID"))
    > Menu1.Items.Add(MainItem)
    > Next
    > End Sub
    >
    > Private Sub DoSubMenuItems(ByVal i_Parent As skmMenu.MenuItem, ByVal

    i_ParentID As Integer)
    > 'This Subroutine handles all else
    > Dim dsSubItems As New DataSet
    > dsSubItems = GetMenuDataSet(i_ParentID)
    > For Each dr As DataRow In dsSubItems.Tables(0).Rows
    > 'Get the values from the DataRow
    > Dim MenuText As String = CstrNull(dr.Item("mnuName"))
    > Dim MenuURL As String = CstrNull(dr.Item("mnuURL"))
    > Dim HasChildren As Boolean = (CLng0(dr.Item("Children")) > 0)
    > Dim MenuMouseOver As String =

    CstrNull(dr.Item("mnuMouseOver"))
    > 'Create New SubMenu Item and Set it's properties
    > Dim NewSubMenu As New skmMenu.MenuItem
    > NewSubMenu.Text = MenuText
    > NewSubMenu.ToolTip = MenuMouseOver
    > NewSubMenu.Url = MenuURL
    > If HasChildren Then 'Has Items Under It, so call ourself to

    do children items
    > NewSubMenu.Text += " >>" 'Add Text to signify that is has

    children
    > DoSubMenuItems(NewSubMenu, dr.Item("MenuID"))
    > End If
    > i_Parent.SubItems.Add(NewSubMenu) 'Finally add item to

    Parent
    > Next
    > End Sub
    >
    > 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; Integrated Security=SSPI")
    > Dim objAdapter As New SqlDataAdapter
    > Dim ds As New DataSet
    > objAdapter = New SqlDataAdapter("buildMenu " & i_ParentID,

    objConn)
    > ds = New DataSet
    > objAdapter.Fill(ds, "Menu")
    > objAdapter.Dispose()
    > objConn.Close()
    > End Function
    >
    > Private Function CstrNull(ByVal i_Value) As String
    > 'Take in a Value, and spits back a String no matter what
    > '(avoids having to explicitly checking for DBNull)
    > Try
    > Return CStr(i_Value)
    > Catch
    > Return ""
    > End Try
    > End Function
    >
    > Private Function CLng0(ByVal i_Value) As Long
    > 'Takes in a Value and spits back a Long no matter what
    > '(avoids having to explicitly checking for DBNull or invalid #'s)
    > Try
    > Return CLng(i_Value)
    > Catch
    > Return 0
    > End Try
    > End Function
    >
    >
    > End Class
    >
     
    Marina, Jun 29, 2004
    #1
    1. Advertising

  2. I don't get it! What have I missed??? Sorry reasonably new to ASP.NET!

    Thanks
     
    =?Utf-8?B?VGltOjouLg==?=, Jun 29, 2004
    #2
    1. Advertising

  3. Marina

    Marina Guest

    You missed a 'Return ds' statement at the end of that function.

    Do you think it somehow knows that you actually meant for it to return that
    object? You need to put 'Return' statement at the end of all functions, so
    they actually return a value. Right now that function is not returning
    anything.

    Also, like I said, try using the debugger to see what the problem is - it
    will be faster and you will learn more then by waiting for newsgroup
    responses.

    "Tim::.." <myatix_at_hotmail.com> wrote in message
    news:...
    > I don't get it! What have I missed??? Sorry reasonably new to ASP.NET!
    >
    > Thanks
    >
     
    Marina, Jun 29, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim T

    do you know why this won't work?

    Tim T, Nov 11, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    1,476
    Tim T
    Nov 12, 2003
  2. Roy
    Replies:
    1
    Views:
    308
  3. Chad
    Replies:
    4
    Views:
    8,375
  4. =?Utf-8?B?SmFzb24=?=

    Why Custom Validators WON'T work in FoxFire?

    =?Utf-8?B?SmFzb24=?=, Jun 29, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    635
    Paul Glavich [MVP ASP.NET]
    Aug 4, 2005
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,076
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page