in my database there is some row which is null and how can i use nullable type or how can i skip nullable row in linq? but i prefer to use nullable type rather than skip rows (see image)
Asked
Active
Viewed 88 times
-1
-
have you tried b.field
– Daniel Feb 13 '19 at 15:33 -
2have you tried `b.Field
("FloatingPNL")`? – BugCatcherJoe Feb 13 '19 at 15:34 -
1Possible duplicate of [Linq to DataTable - Cannot cast DBNull](https://stackoverflow.com/questions/7091379/linq-to-datatable-cannot-cast-dbnull) – Tvde1 Feb 13 '19 at 15:53
-
1Please don't post images of code. – a stone arachnid Feb 13 '19 at 17:32
3 Answers
1
You can't cast null to a non nullable type (decimal)
You should update your generic type to a nullable type like the below:
From
let floatingPNL1 = b.Field<decimal>("FloatingPNL")
To
let floatingPNL1 = b.Field<decimal?>("FloatingPNL")
Another option would be to use an ORM such as dapper, much easier to use and handles the object mapping for you.

Daniel
- 976
- 5
- 14