I have this line of code which loads data from a database table into a list:
Dim facilities As New List(Of FacilityData)()
facilities.AddRange(ds.Tables(0).Rows.OfType(Of DataRow)().Select(Function(r) FacilityData.FromRow(r)))
Problem is some of the data columns are integers, and sometimes that integer field is Null in the database, which really makes the program unhappy (crash) when it hits the facilities.AddRange
Is there an easy way to fix this so default values are used if certain fields are null?
I do have a FacilityData
class constructor that was supposed to take care of these problems:
public class FacilityData
Active = true;
public FacilityData(DataRow DRow)
SiteID = DRow.IsNull("SiteID") ? 0 : (int) DRow["SiteID"];
but it's using the public FacilityData()
constructor instead of the public FacilityData(DataRow DRow)
constructor that has all the fix it code for Null fields.