日期:2014-05-20  浏览次数:20786 次

当DateTime为null的时候 如何转换我?
C# code

                var query = from order in orders.AsEnumerable()
                            orderby order.Field<int>("Status") ascending, order.Field<DateTime>("CreateOn") descending
                            select new
                            {
                                OrderID = order.Field<int>("OrderID"),
                                ProductName = order.Field<string>("ProductName"),
                                Price = order.Field<decimal>("Price"),
                                Count = order.Field<int>("Count"),
                                Status = order.Field<int>("Status"),
                                PayMoney = order.Field<decimal>("PayMoney"),
                                PayDate = order.Field<DateTime>("PayDate"),
                                CheckName = order.Field<string>("CheckName"),
                                Tel = order.Field<string>("Tel"),
                                CheckAddress = order.Field<string>("CheckAddress"),
                                Freight = order.Field<int>("Freight")
                            };


PayDate = order.Field<DateTime>("PayDate"),就是这句
当字段"PayDate"为的时候,程序会出错

请问如何转换?
不是说Field<T>()可以支持null的吗?

------解决方案--------------------
order.Field<DateTime?>

可空结构才允许null值...