473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Formating currency on label

Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0
Jun 27 '08 #1
4 3608
"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not apply
{0:c} to it. Since it only applicable to Decimal datatypes (numerics
probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.
"Paulo" <er********@terra.com.brwrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0

Jun 27 '08 #2
George, I found something on google:

lblPreco.Text = string.Format("{0:c}", reader[1]);

Thank you very much!

"George Ter-Saakov" <gt****@cardone.comescreveu na mensagem
news:%2****************@TK2MSFTNGP04.phx.gbl...
"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not apply
{0:c} to it. Since it only applicable to Decimal datatypes (numerics
probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.
"Paulo" <er********@terra.com.brwrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
>Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0


Jun 27 '08 #3
Agreed.

You should always pick the granular "get".

..GetString()
..GetDateTime
..GetInt32()
etc, etc.

Instead of .GetValue() ... or how you're (mis) using the ToString().

"George Ter-Saakov" <gt****@cardone.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not apply
{0:c} to it. Since it only applicable to Decimal datatypes (numerics
probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.
"Paulo" <er********@terra.com.brwrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
>Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0


Jun 27 '08 #4
That is pretty much the same thing except slower :)

reader[1] returns an object that is actually has type Decimal.
Then you leave string.Format to figure it out and apply {0:c} accordingly.

with reader.GetDecimal(1).ToString("c") the guessing of which type reader[1]
is already done by you. Since GetDecimal returns Decimal.

George.
"Paulo" <er********@terra.com.brwrote in message
news:OK**************@TK2MSFTNGP04.phx.gbl...
George, I found something on google:

lblPreco.Text = string.Format("{0:c}", reader[1]);

Thank you very much!

"George Ter-Saakov" <gt****@cardone.comescreveu na mensagem
news:%2****************@TK2MSFTNGP04.phx.gbl...
>"Show currency" is kind of vague....as "does not work"....I bet it works
just does not give you result you want :)

After you did reader[1].ToString() it becomes string and you can not
apply {0:c} to it. Since it only applicable to Decimal datatypes
(numerics probably too).

Not sure why you doing it that way

lblPreco.Text = reader.GetDecimal(1).ToString("c") should work...
Plus it's much faster ....

George.
"Paulo" <er********@terra.com.brwrote in message
news:eG**************@TK2MSFTNGP05.phx.gbl...
>>Hi, I need to show on a label the data coming from db and it must show a
currency... I'm using a SqlDataReader reader, but doesnt work...

lblPreco.Text = Eval(reader[1].ToString(), "{0:c}");

Can you help me ? Thanks!

VS 2005 asp.net C# 2.0



Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bill Partridge | last post by:
I am being very dumb... I am coverting an invoice value to a decimal and displaying the result on a VB.net 2003 form. However, I only want to display the result to 2 decimal places and I am...
2
by: Dalan | last post by:
This should not be an issue, but it is. I'm sure that someone knows what little piece of code is needed too persuade Access 97 to include a currency format for labels (Avery, mailing type). Have...
2
by: hallman | last post by:
I have data that I would like to format just so: 2000 to be $2,000 -2000 to be ($2,000) 2000.01 to be $2,000.01 2000.1234 to be $2,000.1234 The 'canned' Currency format type *rounds* the...
2
by: VB Programmer | last post by:
I have a datalist that contains a label for each time to hold pricing info. In the Access db everything is stored in a currency format. But, when the label displays the info it's not in currency...
7
by: nbohana | last post by:
I have a textbox that displays money, I cannot find out how to format it so it displayes like '$123.00' what i get now is '123.00'. Can someone point me in the right direction? Thanks in...
14
by: Scott M. | last post by:
Ok, this is driving me nuts... I am using VS.NET 2003 and trying to take an item out of a row in a loosely-typed dataset and place it in a label as a currency. As it is now, I am getting my...
0
by: Akinyemi | last post by:
I am currently puting finishing touches to a Tax Computin Software. But I am worried about the number of decimal place the program displays - Four decimal place. And some of the fields display only...
1
by: Ikraams | last post by:
I have two sheets (A3 size) reports. Both are same except the values in different currency. The other is paste link to the first. The problem is when I add text then have to maually adjust rows and...
9
by: najmi | last post by:
hai guys...do you know how to formating the currency data from database into java form
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.