I have a function that takes in a number of parameters.. it then does a db insert.
i have a foreign key on one of the fields (modelID)
i want to pass a NULL if no model ID is selected.
i tried the following:
Dim model As Nullable(Of Integer)
If ddlModel.SelectedValue = "Other" Then
'add new model
model = cSource.InsertModel(txtModel.Text, ddlManuf.SelectedValue)
ElseIf ddlModel.SelectedValue = "0" Then
model = Nothing
Else
model = ddlModel.SelectedValue
End If
but now i get an error saying: Nullable object must have a value.
how can i fix this? if i pass in a 0, it does not insert because it breaks the DB constraints :(