Last post Jun 09, 2009 07:45 PM by Madog
Jun 05, 2009 05:19 AM|Madog|LINK
I receive a syntax error on SetDiabetic_TypeNull() saying it doesn't provide a value.
I am trying to set it to null because the field in the table is set to not required.
To get it to work, I have to set the field to 'nothing', which then updates the database field with
zero. This is not want I want.
Why can't I use the datarow class method SetDiabetic_TypeNull()
Jun 05, 2009 07:50 AM|MetalAsp.Net|LINK
Try seeting it like this:
survey_dr.Diabetic_Type = DBNull.Value
Jun 09, 2009 07:45 PM|Madog|LINK
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:
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.
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: