Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert null value for byte field

Status
Not open for further replies.

zerkat

Programmer
Jul 12, 2007
103
US
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?
 
ok - must have had some value somewhere else tried setting the value to nothing and it worked this time....that's what i get for working on a friday afternoon!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top