Convert to currency using ToString("c")

hi experts...seems like this should be really simple..i'm creating a datareader that will always return a known/static # of records...then looping thru it assigning values to an arraylist....i then want to turn around and manually assign the arraylist values to each of my dynamically created labels...something like this:
SqlDataReader dr = mycmd.ExecuteReader();
ArrayList ar = new ArrayList();

while(dr.Read())
{
      ar.Add(dr.GetValue(1));
}
((Label) Page.FindControl("lbl_1")).Text = ar[0].ToString("c");
((Label) Page.FindControl("lbl_2")).Text = ar[1].ToString("c");
etc...

the values from the database are in decimal format by default....i need the value that i write to the label to be formatted as currency - everywhere else in the app, ToString("c") works fine...but using it in this context i get the error:
No overload for method 'ToString' takes '1' arguments
and the project won't compile....any idea why it's not working in this scenario?
friskyweaselAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
Hi friskyweasel,

This is because ar[0] returns an object type and an object cannot be converted to currency. Cast it as decimal first (my C# syntax may not be 100% good):

((decimal)ar[0]).ToString("c");

Cheers!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
friskyweaselAuthor Commented:
i got a 'specific cast is not valid' error with that one emoreau, but your answer to the question was 100% correct...that never even occurred to me - i was going in circles.....

thanks!



 
this was the syntax that worked for me
Convert.ToDecimal(ar[0]).ToString("c");
Éric MoreauSenior .Net ConsultantCommented:
friskyweasel,

I knew my syntax was probably having problems (because I am a VB guy) and I tried to cast it as you normally do in C#!
friskyweaselAuthor Commented:
yup - shoot man that's not a problem at all - you came up with 95% of what I needed, which was the REASON it wasn't working...and you were correct - i just put the code i used out there in case anyone else stumbled across the question...

i knew it had to be something simple, but was just drawing a complete blank! thanks again for your help : )
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.