I am doing this with LINQ:
// let use Linq
var DateMarket = from p in Orders_From_CRD.AsEnumerable()
where p.Field<Double>("Fill_ID") != null
select OrderTable.Rows.Add(p.Field<DateTime>("trade_date"), p.Field<string>("ticker"),
p.Field<Double>("EXEC_QTY"), p.Field<Double>("EXEC_PRICE"));
TradeTable = DateMarket.CopyToDataTable();
But I have an error telling me
Cannot cast DBNull.Value to type 'System.Double'. Please use a nullable type.
Do you know how to cast nullable type in this case ?
I tried <Double?>
and I got 'Specified cast is not valid.'
Java primitive types (such as int , double , or float ) cannot have null values, which you must consider in choosing your result expression and host expression types.
In the C# programming language, all basic numeric data types (int, float, double, bool, and others) are value types. These types can never be set to null.
Short answer: You can't. A double can only contain a valid double-precision floating point value.
If you want to assign null value or no value for this double variable then you have to give value like 0.0.
You could use:
p.Field<Double?>
T?
is shorthand for Nullable<T>
, a wrapper for a value type that allows null values.
Use the type :
Double?
when you need a nullable double
by default, double can't be assigned null values. The solution to this problem is to use a nullable type : Double?
try this:
var DateMarket = from p in Orders_From_CRD.AsEnumerable()
where p.Field<Double?>("Fill_ID") != null
select OrderTable.Rows.Add(p.Field<DateTime>("trade_date"), p.Field<string>("ticker"),
p.Field<Double?>("EXEC_QTY"), p.Field<Double?>("EXEC_PRICE"));
TradeTable = DateMarket.CopyToDataTable();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With