This should be easy. I have a combobox with state names. If the country is not US we don't want to require the state. The value of the state combobox is a tinyInt which the entity framework in VS 2010 converts to a byte. So I am trying to test for this like so:
If statecombobox.selectedValue = 0 Then
StateIdField = Nothing
End If
But this sets the stateIdField to 0 and that fails because of the constraint on the db - nothing in state table with an ID of 0. Our DBA does not want 0 in the db if a person doesn't select anything. Tried setting it to DBNull.value but just receive error that cannot convert a byte field to Null. Tried also to see if it would take the actual string of null but that didn't work either because cannot convert string to byte. Any one have any workarounds for this?
If statecombobox.selectedValue = 0 Then
StateIdField = Nothing
End If
But this sets the stateIdField to 0 and that fails because of the constraint on the db - nothing in state table with an ID of 0. Our DBA does not want 0 in the db if a person doesn't select anything. Tried setting it to DBNull.value but just receive error that cannot convert a byte field to Null. Tried also to see if it would take the actual string of null but that didn't work either because cannot convert string to byte. Any one have any workarounds for this?