0
在数据库上我有一个字段smalldatetime。 在C#的一面,它得到了DateTime?
类型,但如果我尝试这样做:Linq到Sql的DateTime?
<%=MyAppTable.MyDataField%>
我不能访问的方法,如ToShortDateTime()
。我不认为我需要在那里演员?
在数据库上我有一个字段smalldatetime。 在C#的一面,它得到了DateTime?
类型,但如果我尝试这样做:Linq到Sql的DateTime?
<%=MyAppTable.MyDataField%>
我不能访问的方法,如ToShortDateTime()
。我不认为我需要在那里演员?
因为它是你可能需要做这样的事情可为空的日期时间:
<%= MyAppTable.MyDataField.Value.ToShortDateTime() %>
这样做,确保它有一个价值,虽然之前。
DateTime?是可以空的类型。您必须将其转换为DateTime
((DateTime)MyAppTable.MyDataField).ToShortDateTime()
小心空引用异常。