-
4
Answers
-
Last Activity:
long time ago,
DeanAgar
Your question has been submitted and is awaiting moderation.
Thank you for reporting this content, moderators have been notified of your submission.
In my database I have a foreign key field that is an integer and accepts nulls because in some situations the user can't provide a measurement. When I create a new record from DotNetNuke it throws an error about foreign key conflict because it saves it as 0 by default while there are no 0s in the lookup table. In my info class, I have changed the field type from int to int?
That solved my problem. However I come across another situation where I can retrieve records that have the foreign key set to null, but any records with a measurement value throws an error below when the stored procedure is executed:
A critical error has occurred. Invalid cast from 'System.Int32' to 'System.Nullable`1[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]'.
Here is my property from the info class that stores the foreign key field:
private int? _EQSWLMeasurement
public int? EQSWLMeasurement
{
get
{
if (_EQSWLMeasurement.HasValue)
{
return (int)_EQSWLMeasurement.Value;
}
else
{
return null;
}
}
set
{
_EQSWLMeasurement = value;
}
}
Any idea how I can fix the issue, or is there anything obvious that I've missed out?