使用实体框架将日期作为字符串传递给Crystal Report

问题描述

当DateOfBirth为Null时,我想将类似“-”的字符串传递给Crystal Report,但出现此错误:

System.FormatException:'字符串未被识别为有效的DateTime。'

使用此代码时:

 .Select(u => new
{

 u.EmployeeCode,u.EmployeeName,JopName = string.IsNullOrEmpty(u.JopName) ? "-" : u.JopName,Date_Hiring = u.Date_Hiring.GetValueOrDefault(),AdministrationName = string.IsNullOrEmpty(u.AdministrationName) ? "-" : u.AdministrationName,DepartmentName = string.IsNullOrEmpty(u.DepartmentName) ? "-" : u.DepartmentName,PranchName = string.IsNullOrEmpty(u.PranchName) ? "-" : u.PranchName,DateOfBirth =Convert.ToString(u.DateOfBirth) == string.Empty ? DateTime.Parse("-") : u.DateOfBirth
})
 .ToList();

这是我的课程:

public partial class SR1_Result
 {
   public int EmployeeCode { get; set; }
   public string EmployeeName { get; set; }
   public string JopName { get; set; }
   public Nullable<System.DateTime> Date_Hiring { get; set; }
   public Nullable<double> Nat_Salary { get; set; }
   public string AdministrationName { get; set; }
   public string DepartmentName { get; set; }
   public string PranchName { get; set; }
   public string MobilePersonalNo { get; set; }
   public string MobileWorkNo { get; set; }
   public Nullable<System.DateTime> DateOfBirth { get; set; }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)