且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将空值分配给datetime对象

更新时间:2023-02-09 14:23:41

Dim dt as DateTime = System.DBNull.Value


如果您使用的是.Net 2.0或更高版本,则始终可以使用可为空的类型.

将您的字段声明为 DateTime? dt;
然后设置dt = null;

更新:
在VB.NET中,使用此命令:
If you are using .Net 2.0 or greater, you can always use a nullable type.

Declare your field as DateTime? dt;
Then set dt = null;

UPDATE:
In VB.NET, use this:
Dim dt As System.Nullable(Of DateTime)
dt = Nothing