I have trouble to convert from decimal to hex.
Here is my code:
select new
{
MessageID = table1.Field<Int32?>("MessageID"),
MessageIDHex = (String)table1.Field<Int32>("MessageID").ToString("X")
}
It gives me Error
with DBNUll.Value cant not change to System.In32
So I have tried
MessageIDHex= (String)table1.Field<Int32?>("MessageID").ToString("X")}
but it gives me another error.
How can I fix it or it does have another way to solve it.
Apparently,
MessageIDcan be DBNull. The simplest solution is to read the value as a nullable int (to prevent the conversion error from occurring). If you useFieldwith a nullable type,DBNullis automatically converted tonull, which can then be coerced to 0 with the??operator:Alternatively, if you prefer, you can have DBNull values in the database result in an empty or a null string for
MessageIDHex: