i have integer variable like this:
Dim valetid as integer
If cvalettype.Checked Then
valetid = RecordID("vtid", "VType_tbl", "Vtype", cmbvalettype.Text)
Else
valetid = 0
End If
if condition coming to else case the valetid taking 0 value.that is saving in database as 0 only. if condition coming to else case i want to save my valetid in mydatabase as Null(now in my database saving valetid as 0).in my database Valetid datatype i declared as int.how i can do this?
First, your integer variable has to be nullable in both the VB code and the database. Assuming that the database allows nulls for this field, you can do something like this:
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
Or, as Neolisk prefers it:
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With