我有这样的整数变量:
Dim valetid as integer
If cvalettype.Checked Then
valetid = RecordID("vtid", "VType_tbl", "Vtype", cmbvalettype.Text)
Else
valetid = 0
End If
Run Code Online (Sandbox Code Playgroud)
如果条件进入其他情况,则valetid取0值.即仅将数据库保存为0.如果条件来到其他情况我想将我的valetid保存在mydatabase中为Null(现在在我的数据库中将valetid保存为0).在我的数据库中,我声明为int.how的数据类型我可以这样做吗?
首先,您的整数变量必须在VB代码和数据库中都可以为空.假设数据库允许此字段为空,您可以执行以下操作:
Dim valetid as Integer?
If cvalettype.Checked Then
valetid = RecordID("vtid", "VType_tbl", "Vtype", cmbvalettype.Text)
Else
valetid = Nothing
End If
' Do stuff with your valetid variable here
Run Code Online (Sandbox Code Playgroud)
或者,正如Neolisk所喜欢的那样:
Dim valetid as Nullable(Of Integer)
If cvalettype.Checked Then
valetid = RecordID("vtid", "VType_tbl", "Vtype", cmbvalettype.Text)
Else
valetid = Nothing
End If
' Do stuff with your valetid variable here
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12562 次 |
最近记录: |