I get an error when choosing from a row. AsEnumerable (). I am using the following code ...
var rows = ds.Tables[0].AsEnumerable(); trafficData = rows.Select(row => new tdDataDC { CalculationCount = row.Field<Int64>("biCalculationCountSeqID") , Zone = row.Field<Int16>("siFkZoneId") , Miles = row.Field<decimal>("dcMiles") , Plaza = row.Field<Int16>("siFkPlazaId") , VehicleCount = row.Field<int>("iVehicleCount") });
In most cases, this works well, but when there are NULLS in the database, I get this error. "You cannot use DBNull.Value to enter" System.Int16 ". Use a type with a null name .." How can I fix this? I don't want my datacontracts to be Nullable types, I would like to use ternary or something else, and if the value is NULL, just use 0. Is this possible?
Thanks for any help,
~ Ck
null c # linq dbnull ienumerable
Hcabnettek
source share