On top of all the other suggestions here, I have to question you
converting to a decimal, and then back to a string. The only way I can see
this being of use is if the value in dr[2] is a number in string format,
which you want to express in a different format.
Otherwise, the value in dr[2] is a numeric type, and you should be able
to call ToString directly on it, you just have to perform a cast on the
value returned so that you can make the appropriate call:
((decimal) dr[2]).ToString("#,##0.00");
If the type of dr[2] is something other than decimal, I recommend
casting to that type, since you aren't going to gain anything by casting any
numeric type to decimal, and then formatting the string. If you had to do
further work with it, then I would understand the cast to decimal (for the
need for precision), but that isn't the case here.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Bob" <Go****@Yahoo.Comwrote in message
news:11**********************@l70g2000hse.googlegr oups.com...
>
Hello folks.
I use this formating but if the value in dr[0] is a null it generates
an error
"Object cannot be cast from DBNull to other types."
Anybody know how I can deal with nulls?
Thanks,
Bob