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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric field of Byte default value

Status
Not open for further replies.

shaunk

Programmer
Aug 20, 2001
402
0
0
AU
The Access verison is 2003.
I have a table with a numeric field of type byte.
I have set it to 'not required' with no default value.
I am updating the field from a ASP.Net(VB) webform and am setting the field to 'nothing' if the corresponding webform field is not completed.
However, on update, it is populating the field with zero.
I am not sure if this is a .net problem or that is how Access behaves with number fields. I would have thought it unlikely as zero is a valid numeric value as opposed to just being empty.

Thanks

The risk with keeping an open mind is having your brains fall out.
Shaunk

 
try null when you update

Remember amateurs built the ark - professionals built the Titanic

[flush]
 
I'm afraid that doesn't work as it complains about not being able to convert a type of system DBNull to Byte.I ended up doing a death march through Google and found the problem posted many times and no actual solution. So here it is:

What is expected is to use the inbuilt datarow class methods to set the field to null before update. The syntax as it applies to my situation is survey_dr.SetDiabetic_TypeNull(). So for any other field it would be survey_dr.Set@FieldnameNull where @Fieldname is the name of the field.
The full code is:

If Not Diabetic_Type.HasValue Then
survey_dr.SetDiabetic_TypeNull()
Else
survey_dr.Diabetic_Type = Diabetic_Type
End If

Note the use of Diabetic_Type.HasValue to check if the nullable type has a value.

On extraction there are inbuilt methods to test if the nullable field extracted from the database contains nulls which must be employed to avoid errors.

If Survey_dt(0).IsDiabetic_TypeNull Then
Me.rblDiabeticType.SelectedValue = Nothing
Else
Me.rblDiabeticType.SelectedValue = Survey_dt(0).Diabetic_Type
End If

I had a look at the field properties in the datatable generated by the typed dataset, and under the attribute DataType there is no type listed as Nullable of (Byte) or Nullable of anything for that matter. So it will recieve a conversion error when trying to set it to null. I am guessing this is because the standard types such as integer, byte etc are value types which always have a default value and cannot be null. Nullable types are actually reference types. There is a discussion of nullable types here:



The risk with keeping an open mind is having your brains fall out.
Shaunk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top