I have an SQL database that I'm extracting data out of. However, some of that data isn't measured and is therefore NULL. I've been able to avoid some null values using this method:
if (dataItem.Feature1!= null) {
trainingCategorial.Feature1= (float)dataItem.Feature1;
}
else {
trainingCategorial.Feature1= float.NaN;
}
Where dataItem is the my dataset which I'm iterating through with foreach.
foreach (dataItem in dataset)
However, now I have the same issue but with an equation:
if(dataItem.CalculateFeature2(afdKenm, (decimal)dataItem.Feature3) != null)
{
trainingCategorial.Feature2 =
dataItem.CalculateFeature2(afdKenm, (decimal)dataItem.Feature3) > 0;
}
The goal of the code is to create a boolean of Feature2. I've checked and it didn't seem as feature3 has any NULL values. My question lies in the way that my c# code doesn't even want to check the dataItem.CalculateFeatures2 before giving the error. It just immediately says that "Nullable object must have a value".
Can anyone help me with this? Thank you in advance!
I tried to check if there were null values based on:
However, this did not work and there were indeed null values in my database. I was confused as I had already used a similar method beforehand, but there weren't any null values in that dataset. Eventually I just calculated Feature3 myself, and now the code indeed works.
Thank you for your help! And for other people struggeling with this issue: If you're using an
Use a breakpoint in the if function, because if it doesn't go in there in your debug than you also know that there are NULL values in your dataset and you can handle them appropiately.