Dan Holmes wrote:
i have a datareader that pulls a field of type numeric(18, 0). the
debugger shows the field as {decimal}. I want to cast it to an int.
This doesn't work (int)dr["field1"]:. Is that because the definition of
the column would overflow an int? So i would have to do something like
int.Parse(dr["field1"].ToString());
I believe that you have to cast in two steps... that you can't unbox
the value and cast it all in one go. If you say
decimal f1 = (decimal)dr["field1"];
then this will unbox the value, then you can say:
int i1 = (int)f1;
to do the cast. You might even be able to do this:
int i1 = (int)((decimal)dr["field1"]);
but I'm not 100% sure without trying it myself.