Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在VB.NET中将日期变量设置为null_Vb.net_Date_Null - Fatal编程技术网

如何在VB.NET中将日期变量设置为null

如何在VB.NET中将日期变量设置为null,vb.net,date,null,Vb.net,Date,Null,我想将DOB变量赋值为null Dim DOB As Date = DTPSdob.Value Dim datestring As String = DOB.ToString("d") If chkSdob.Checked = False Then DOB = 'I want to assign here DOB variable as null' Else DOB = datestring End If “DateTime是一种值类型(结构),不能像所有.Net值类型

我想将
DOB
变量赋值为null

Dim DOB As Date = DTPSdob.Value
Dim datestring As String = DOB.ToString("d")
If chkSdob.Checked = False Then
      DOB = 'I want to assign here DOB variable as null'
Else
      DOB = datestring
End If

“DateTime是一种值类型(结构),不能像所有.Net值类型那样设置为null或nothing。DateTime值的默认值是日期部分为零,时间部分为12:00:00 AM。”

使用可为空的日期时间

    Dim DOB As Nullable(Of Date) = Date.Now
    Dim datestring As String = DOB.Value.ToString("d")
    DOB = Nothing

将DOB从日期变量更改为对象变量。然后可以不向变量传递任何内容或有效日期。然后可以使用该变量更新数据库

dim DOB as object = nothing
If chkSdob.Checked = True Then
  DOB = datestring
end if

应该是DOB.Value.ToStrin(“d”),更新后的答案,现在请检查您已经给出了答案。不要试图通过编辑来纠正其他答案。为什么你想要两个完全相同的答案?请使用评论系统指出错误。谢谢。网络问题。同样的答案发布了两次,有人删除了第二个,谢谢,不管是谁,这不是我的意思。你似乎有,所以它看起来和你的一样。我以为问题是关于日期而不是日期时间?@AltF4_uuu利用它的力量,而不是语法为什么要麻烦?当你不知道问题是什么的时候