请解决这个Erro [英] Please Solve this Erro

查看:137
本文介绍了请解决这个Erro的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MenuItem menu = new MenuItem();
            if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            SqlCommand cmd = new SqlCommand("SP_DemoMenu", con);
            cmd.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();

            SqlDataAdapter adpt = new SqlDataAdapter(cmd);
            adpt.Fill(ds);
            con.Close();
          
           foreach (DataRowView item in mainMen)
            {
                MenuItem Mmnu = new MenuItem(item["MenuName"].ToString(),
                item["MenuId"].ToString(), "", item["Url"].ToString());
                mainMenu.Items.Add(Mmnu);
                subMenu.RowFilter = "MenuId = " + Mmnu.Value;
                foreach (DataRowView subItem in subMenu)
                {
                MenuItem sMnu = new MenuItem(subItem["SubMenuName"].ToString(), 
                subItem["SubMenuId"].ToString(), "", subItem["MenuUrl"].ToString());
                mainMenu.Items[Convert.ToInt32(Mmnu.Value)-1].ChildItems.Add(sMnu);
                subChildMenu.RowFilter = "MenuId = " + Mmnu.Value + " And SubMenuID = " + sMnu.Value;
                foreach (DataRowView childItem in subChildMenu)
                {
                MenuItem chldMnu = new MenuItem(childItem["ChildMenuName"].ToString(),"","", childItem["MenuUrl"].ToString());
            mainMenu.Items[Convert.ToInt32(Mmnu.Value) - 1].ChildItems[Convert.ToInt32(sMnu.Value) - 1].ChildItems.Add(chldMnu);
        }
    }    
}





给出错误





Error Given

Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0103: The name 'mainMen' does not exist in the current context

Source Error:


Line 30:             con.Close();
Line 31:           
Line 32:            foreach (DataRowView item in mainMen)
Line 33:             {
Line 34:                 MenuItem Mmnu = new MenuItem(item["MenuName"].ToString(),

推荐答案

好吧,没有 mainMen (不是缺失的u从最后开始),但即使你发布的代码中没有声明 mainMenu 。所以你得到这个错误是很正常的。你会发现这里没有人能够猜猜代码的其余部分是什么样的。

但我很确定,你在 foreach 中迭代的集合不是 mainMen ,既不是 mainMenu ,因为名为 menu 的东西不太可能是一个集合 DataRowView 元素。
Well, there is no mainMen (not the missing "u" from the end), but even no mainMenu declared in the code you posted. So it is quite normal that you get this error. And you will find nobody here able to guess how the rest of your code looks like.
But I am pretty sure, that the collection you are iterating in that foreach is not mainMen, neither mainMenu, since it is unlikely that something called "menu" is a collection of DataRowView elements.


这篇关于请解决这个Erro的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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