我从数据库中查询了一些字段,其中Planstartdate是datetime类型,而且Planstartdate可能为空。 我想将Planstartdate格式化为“yyyy-MM-dd”
DataTable dt = ds.Tables[0];
var query = dt.AsEnumerable()
.Select(dr =>
new InitOverview
{
IID = string.IsNullOrEmpty(dr.Field<string>("IID").ToString()) ? "" : dr.Field<string>("IID"),
ProjectName = string.IsNullOrEmpty(dr.Field<string>("ProjectName")) ? "" : dr.Field<string>("ProjectName"),
TeamLead = string.IsNullOrEmpty(dr.Field<string>("TeamLead")) ? "" : dr.Field<string>("TeamLead"),
Status = string.IsNullOrEmpty(dr.Field<string>("Status")) ? "" : dr.Field<string>("Status"),
OverallStatus = string.IsNullOrEmpty(dr.Field<string>("OverallStatus")) ? "" : dr.Field<string>("OverallStatus"),
Planstartdate = dr.Field<DateTime?>("Planstartdate"),
Planenddate = dr.Field<DateTime?>("Planenddate"),
Actualstartdate = dr.Field<DateTime?>("Actualstartdate"),
Actualenddate = dr.Field<DateTime?>("Actualenddate")
}
).ToList();
有人可以帮忙实现吗?谢谢。