Reputation: 27996
I am using typed data set in my application and I have a data table with two columns which are of System.Int32.AllowDBNULL = true
and NULLVALUE = throw exception and default value = 1. I am using this property of datatable in my code like this:
if (rr.ForenameStatus != -1 && rr.ForenameStatus == 0)
{
}
but I am getting this error:
The value for column 'ForenameStatus' in table 'Registrant' is DBNull.
I tried to change NULLVALUE
of column to NULL
or empty in dataset properties but I get error:
property value is not valid
I tried using this:
if (rr.ForenameStatus != System.DBNull.Value && rr.ForenameStatus == 0)
{
}
but It says Operator != can not be applied to operands of int and dbnull
Please suggest me solution to this.
Upvotes: 0
Views: 1766
Reputation: 2598
Try this:
if (rr.ForenameStatus.ToString()!="" && rr.ForenameStatus == 0)
{
}
This is as an alternative. You may try converting the int value to string and compare against empty string to identify the nulls.
Upvotes: 0
Reputation: 2279
Set AllowDBNULL = true and call IsForenameStatusNull method to check on NULL value.
Upvotes: 1