如何在menu.items.add中替换Null引用 [英] how to replace Null reference in menu.items.add

查看:64
本文介绍了如何在menu.items.add中替换Null引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人可以帮我这个代码吗?



Hello there, could somebody help me with this code?

Dim parentMenu As New MenuItem
Dim sonMenu As New MenuItem
Dim parentItem As New DinamicMenu
Dim sonItem As New DinamicMenu
Dim sel_key, sel_KeyParent As String
Dim Dictionary2 As New DictionaryEntry

For Each Dictionary2 In HashMenu
    sonItem = Dictionary2.Value
    sel_key = Dictionary2.Key

    sonMenu = sonItem.MenuItemObj

    If sel_key.LastIndexOf(".") >= 0 Then
        sel_KeyParent = sel_key.Substring(0, sel_key.LastIndexOf("."))
        parentItem = HashMenu(sel_KeyParent)
        parentMenu = parentItem.MenuItemObj
        parentMenu.MenuItems.Add(sonMenu)
    Else
        Me.MainMenu.MenuItems.Add(sonMenu)
    End If
Next



null引用在运行Me.MainMenu.MenuItems.Add(sonMenu)时显示,如果我只能放在下面就可以了。


null reference was show when running "Me.MainMenu.MenuItems.Add(sonMenu)" if only i can put like below it would be great.

if Me.MainMenu.MenuItems.Add(sonMenu)= null then
Me.MainMenu.MenuItems.Add("blanks")





i从这里找到了这个伟大的参考基于数据库的动态菜单 [ ^ ]

我想尝试使用oracle但是仍然卡在这里。提前谢谢



i found this great reference from here Dynamic Menu Based on Database[^]
and i would like to try in oracle but keep stuck in here. thank you in advance

推荐答案

请阅读我对这个问题的评论。



VB.NET不同来自C#并且不包含 null 引用。而不是null,您需要使用 Nothing [ ^ ]。



但是,如果您想检查数据库字段是否存储可以为空的值,请使用:

Please, read my comment to the question.

VB.NET differs from C# and does not contain null reference. Instead of null, you need to use Nothing[^].

But, if you would like to check if Database field stores nullable value, use this:
If DatabaseField = System.DbNull.Value Then





如需了解更多信息,请参阅: Nullable Value Types(Visual Basic) [ ^ ]


这篇关于如何在menu.items.add中替换Null引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆