Passing a null value to an int is not possible. The int type is mapped to the System.Int32 structure type and is not capable of storing a null value. Only integer values can be stored in there.
There are two ways which i know of how to solve this problem. The first method is using an object in stead of the int type. For example:
object val = 200;
if (val != null)
{
return (int)val;
}
In this way you can set the val variable to a null value or an integer value. In case of an integer value you unbox the value to retrieve the integer value.
A second method is using the SqlInt32 type found in namespace System.Data.SqlTypes which is a SQL type. This type supports nullable values. For example:
SqlInt32 val = SqlInt32.Null;
or
SqlInt32 val = 200;