I am using the SqlDataReader to get values from an SQL table and assign them to their respective variables. But in my table, int and double type columns have null values. So when I try to read a null int and assign it to an int variable, it crashes.
Here is how the values are being assigned to:
public int ID { get; set; }
public int Map { get; set; }
public int TypeID { get; set; }
And this is where they are being read:
while (objSqlDataReader.Read())
{
data= new data();
emissiondata.ID = (int)objSqlDataReader["EFID"];
emissiondata.Map = (int)objSqlDataReader["EFMappingID"];
emissiondata.TypeID =(SqlInt32)objSqlDataReader["MobileTypeID"];
So if any of these is null, even when i'm debugging it, it crashes and doesn't continue.
How do I handle the null values in SQL and how do I assign empty values to my int if it is null?