This is what it is: you cannot use
nullable types. You did not provide declaration of the type of
p
but by some its members in your code I can guess their declarations are like this:
int? Year;
int? TermNo;
Otherwise comparison with
null
I can see in your code would not compile.
You can get rid of '?' in member types and your code should work. If you cannot do it because you need to use the type of
p
which is not declared in your code, you should convert the types to non-nullable. For example, the lines involving the members
Year
and
TermNo
should be modified like this:
Year = p.Year == null ? DateTime.Now.Year : p.Year.Value,
TermNo = p.TermNo == null ? 0 : p.TermNo.Value,
[EDIT]
Also, remember: if you want to use database NULL in ADO.NET, you need to use
System.DBNull
class,
http://msdn.microsoft.com/en-us/library/system.dbnull.aspx[
^].
Probably, this was a root cause of the exception you had.
[END EDIT]
A bonus advice: don't use "", use
string.Empty
instead; in general, avoid
immediate constants, especially string immediate constants by all means, instead, declare and use explicit constants, use resources or data read from data files.
—SA