For this LINQ query I'm getting the exception below:
(from row in ds.Tables[0].AsEnumerable()
where row.Field<string>("Dept_line_code") == DeptCode &&
row.Field<string>("Skill_Name") == skill &&
row.Field<string>("Acct_Code") == account && row.Field<string>("Location") == dtNewTable.Rows[intRow]["Location"].ToString()
select row.Field<int>("Presently_Available") == null ? 0 : row.Field<int>("Presently_Available")
).FirstOrDefault();
Exception information:
Exception type: InvalidCastException
Exception message: Cannot cast DBNull.Value to type 'System.Int32'. Please use a nullable type.
I don't know nullable type and I'm not getting how to use nullable type to overcome this exception.
int
,double
,float
, ...) can't be assigned null values. The solution to this problem is to use a nullable type instead (likeint?
), which is really just a wrapper around the primitive type. – Selvage