首页 新闻 会员 周边 捐助

序列不包含任何元素

0
悬赏园豆:10 [已解决问题] 解决于 2011-03-25 15:26

protected void BindDirctritInfo()
    {
        //获取小区ID
        int disid = Convert.ToInt32(Request.QueryString["d"]);

        var result = from s in ft.T_House_Distirct
                     join mt in ft.T_House_MoneyTrend on s.DistirctId equals mt.DorCId
                     where s.State == 0 && s.DistirctId == disid && mt.TrendType == 1
                     select new
                     {
                         s,
                         mt.AgeMoney
                     };
        lbladdr.Text = result.First().s.Address;//异常详细信息: System.InvalidOperationException: 序列不包含任何元素

        //获取物业名称
        var wy = from s in ft.T_House_WType
                 join hwy in ft.T_House_WuYe on s.WuYeTpyeId equals hwy.WuYeTpyeId
                 join h in ft.T_House_Distirct on hwy.WuYeId equals h.WuYeId
                 where h.DistirctId == disid && h.State == 0
                 select new
                 {
                     s,
                     wygs = hwy.Name,
                 };

        //数据绑定
        lblWuYeType.Text = wy.First().s.Name;
        lblOverTime.Text = Convert.ToString(result.First().s.OverTIme);
        lblGreen.Text = Convert.ToString(result.First().s.Green) + "%";
        var developer = ft.T_House_Developer.Where(o => o.DevelopersId == result.First().s.DevelopersId);
        lbldeveloper.Text = developer.First().Name;
        lblHouseCount.Text = Convert.ToString(result.First().s.Sumcount);

Silence静儿的主页 Silence静儿 | 初学一级 | 园豆:190
提问于:2011-03-23 15:36
< >
分享
最佳答案
-6

在方法最开始设个断点,单步调试一下,看看ID是否有值,看看生成的SQL语句能否在SQL Server里执行。

收获园豆:10
麒麟.NET | 老鸟四级 |园豆:3614 | 2011-03-23 16:07
谢谢^_^
Silence静儿 | 园豆:190 (初学一级) | 2011-03-25 15:26
其他回答(1)
6

用FirstOrDefault或者Find。

First代表一定能找到,找不到就抛出异常

一一一 | 园豆:202 (菜鸟二级) | 2013-05-21 15:39
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册