Saturday 27 July 2019

System.InvalidCastException: Object cannot be cast from DBNull to other types

System.InvalidCastException: Object cannot be cast from DBNull to other types. at System.DBNull.System.IConvertible.ToInt32(IFormatProvider provider) at WreckerTowAPI.Controllers.SomeController.Save(List`1 obj)
if (!Convert.IsDBNull(StatusIdOUT.Value))
{
  regResp.Id = Convert.ToInt32(StatusIdOUT.Value);
}
else
{
  regResp.Id = 0;
}