首页 新闻 会员 周边 捐助

不能将 Null 值赋给类型为 System.Boolean (不可为 null 的值类型)的成员

0
[已关闭问题]

 protected void Bind(IQueryable<Fin_StudentLoan> items)
        {
            gvStuLoan.DataSource = from s in items
                                   select new
                                   {
                                       ID = s.ID,
                                       Number = s.StuNumber,
                                       Name = s.Fin_CanLoanStu.Fin_Poverty.Sms_Student.Name,
                                       Class = s.Fin_CanLoanStu.Fin_Poverty.Sms_Student.Inf_Class1.ClassName,
                                       Major = s.Fin_CanLoanStu.Fin_Poverty.Sms_Student.Inf_Class1.Inf_Major.MajorName,
                                       College = s.Fin_CanLoanStu.Fin_Poverty.Sms_Student.Inf_Class1.Inf_Major.Inf_College.CollegeName,
                                       BankName = s.Fin_BankName.BankName,
                                       BankCardNumber = s.BankCardNumber,
                                       MPhone = s.Fin_CanLoanStu.Fin_Poverty.Sms_Student.MPhone,
                                       AcaYeaName = s.Fin_AcacemicYear.AcaYeaName,
                                       LoanAmount = s.LoanAmount,
                                       ContractNum = s.ContractNum,
                                       StartDate = s.StartDate.ToString() != "" ? Convert.ToDateTime(s.StartDate).ToShortDateString() : null,
                                       ExpireDate = s.ExpireDate.ToString() != "" ? Convert.ToDateTime(s.ExpireDate).ToShortDateString() : null,
                                       //IsRepayed = s.IsRepayed.ToString() != "" ? (bool)s.IsRepayed ? true : false : false,
                                       //IsRepayed = s.IsRepayed.HasValue ? ((bool)s.IsRepayed ? true : false) : false,
                                       IsRepayed = (bool)s.IsRepayed ? "已还清" : "未还清",
                                      //IsRepayed = "4545"
                                   };
            gvStuLoan.DataBind();//这个位置抛出异常
        }

语句抛出异常如下:

不能将 Null 值赋给类型为 System.Boolean (不可为 null 的值类型)的成员

 

我把IsRepayed 删除了还报错!以上方法都试过,总是报错!【运行时】

                                <asp:Label ID="lblIsRepayed" Text='<%#Eval("IsRepayed ")%>'  runat="server" ></asp:Label>

问题补充: 大家都跟我一样,都以为是IsRepayed这里有问题,但我可以确定这里是没有问题的了!测试发现时那两个日期型出错了! 但不知道为什么错了,错在那里?
djune的主页 djune | 初学一级 | 园豆:150
提问于:2009-08-28 19:04
< >
分享
其他回答(3)
1

错误信息提供不够详细,可能是   (bool)s.IsRepayed   这里出的错

skyedge | 园豆:275 (菜鸟二级) | 2009-08-28 19:26
0

s.IsRepayed 取出来是null值,(bool)s.IsRepayed 强制转换时出错。

eaglet | 园豆:17139 (专家六级) | 2009-08-29 09:19
0

楼上正解,你可以给这个字段设置默认值,或从数据库取数据时过滤掉为Null的记录。

伽马科技.攻城师 | 园豆:1303 (小虾三级) | 2009-08-29 14:49
0

IsRepayed被定义成了可空类型,bool?  IsRepayed  ,bool? 类型的变量时没办法直接赋值给bool型的

吴畏 | 园豆:426 (菜鸟二级) | 2009-09-10 09:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册