为什么GetFieldValue为此DateTime返回null

本文关键字:返回 null DateTime 为此 GetFieldValue 为什么 | 更新日期: 2023-09-27 18:25:54

我有一个DataTable,它的数据被馈送到一个class:中

MyProperty = myDataRow.GetFieldValue("MyPropertyColumn", DataUtils.NullDateTime);

属性MyProperty是一个Nullable DateTime,该列的值为:

'2010-09-27 00:00:00.000'   AS 'MyPropertyColumn',

当调试器遍历上面的第一行代码时,当我希望将MyProperty设置为DataTable中的DateTime时,它为null。这个日期没有被正确解析有什么原因吗?

为什么GetFieldValue为此DateTime返回null

列值需要作为DateTime而不是字符串传入,因此:

CONVERT(DATETIME, '2010-09-27 00:00:00.000') AS 'MyPropertyColumn',