I want to retrieve decimal values from the database and I would like to know which is the recommended way to check for null values.
I have seen on MSDN - DBNull.Value F
If you want to check for null and handle it (as opposed to checking for null and alerting the program that it was null) you can use the as
operator with the null-coalescing operator ??
.
So in my program
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
response.Employees.Add(new Employee() { Id = dr["id"] as int? ?? default(int), ImageUrl = dr["Photo"] as string, JobTitle = dr["JobTitle"] as string });
}