Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Format text in label to amount

Reply
Thread Tools

Format text in label to amount

 
 
staeri@gmail.com
Guest
Posts: n/a
 
      01-09-2008
I'm populating a label with an amount like this:

lblBudget.Text = Generic_database_functions.GetValue("SELECT
ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")

I want the amount in the label to be shown as "10.000" not "10000".
How can I format the amount?

I'm very grateful for help!

// S
 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-09-2008
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm populating a label with an amount like this:
>
> lblBudget.Text = Generic_database_functions.GetValue("SELECT
> ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")
>
> I want the amount in the label to be shown as "10.000" not "10000".
> How can I format the amount?



I'm presuming that . is the thousand separator for the culture you're
using...

lblBudget.Text =
Convert.ToDecimal(Generic_database_functions.GetVa lue("SELECT
ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")).ToString("#.##0")


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
 
staeri@gmail.com
Guest
Posts: n/a
 
      01-10-2008
On 9 Jan, 15:02, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> > I'm populating a label with an amount like this:

>
> > lblBudget.Text = Generic_database_functions.GetValue("SELECT
> > ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")

>
> > I want the amount in the label to be shown as "10.000" not "10000".
> > How can I format the amount?

>
> I'm presuming that . is the thousand separator for the culture you're
> using...
>
> lblBudget.Text =
> Convert.ToDecimal(Generic_database_functions.GetVa lue("SELECT
> ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")).ToString("#.##0")
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


Thank you for the help. Unfortunately I receive error message: "Input
string was not in a correct format".

(Yes, "." is the thousand separator).

// S
 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-10-2008
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

>> lblBudget.Text =
>> Convert.ToDecimal(Generic_database_functions.GetVa lue("SELECT
>> ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")).ToString("#.##0")

>
> Thank you for the help. Unfortunately I receive error message: "Input
> string was not in a correct format".


What datatype does GetValue return...?


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
staeri@gmail.com
Guest
Posts: n/a
 
      01-10-2008
On 10 Jan, 15:34, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
> >> lblBudget.Text =
> >> Convert.ToDecimal(Generic_database_functions.GetVa lue("SELECT
> >> ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")).ToString("#.##0")

>
> > Thank you for the help. Unfortunately I receive error message: "Input
> > string was not in a correct format".

>
> What datatype does GetValue return...?
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


It returns a string and it looks like this:

Shared Function GetValue(ByVal strSP As String)
Dim myConnection As New SqlConnection(ConnectionString)
Dim myCommand As New SqlCommand(strSP, myConnection)
myConnection.Open()
Dim strValue As String = myCommand.ExecuteScalar().ToString()
myConnection.Close()

Return strValue
End Function

// S
 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-10-2008
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> On 10 Jan, 15:34, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
>> <(E-Mail Removed)> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>> >> lblBudget.Text =
>> >> Convert.ToDecimal(Generic_database_functions.GetVa lue("SELECT
>> >> ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")).ToString("#.##0")

>>
>> > Thank you for the help. Unfortunately I receive error message: "Input
>> > string was not in a correct format".

>>
>> What datatype does GetValue return...?

>
> It returns a string and it looks like this:
>
> Shared Function GetValue(ByVal strSP As String)
> Dim myConnection As New SqlConnection(ConnectionString)
> Dim myCommand As New SqlCommand(strSP, myConnection)
> myConnection.Open()
> Dim strValue As String = myCommand.ExecuteScalar().ToString()
> myConnection.Close()
>
> Return strValue
> End Function


OK, then. Please try the following and tell me where it fails:

Dim strGetValue As String
strGetValue = Generic_database_functions.GetValue("SELECT
ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")
Dim decValue As Decimal
decValue = Convert.ToDecimal(strGetValue)
lblBudget.Text = decValue.ToString("#.##0")



BTW, you should really put some exception handling in your function or, at
the very least, use the Using syntax... As it stands, any error in the
ExecuteScaler line is liable to leave your connection open...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
staeri@gmail.com
Guest
Posts: n/a
 
      01-10-2008
On 10 Jan, 17:10, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
>
>
> > On 10 Jan, 15:34, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:
> >> <(E-Mail Removed)> wrote in message

>
> >>news:(E-Mail Removed)...

>
> >> >> lblBudget.Text =
> >> >> Convert.ToDecimal(Generic_database_functions.GetVa lue("SELECT
> >> >> ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")).ToString("#.##0")

>
> >> > Thank you for the help. Unfortunately I receive error message: "Input
> >> > string was not in a correct format".

>
> >> What datatype does GetValue return...?

>
> > It returns a string and it looks like this:

>
> > Shared Function GetValue(ByVal strSP As String)
> > * * * *Dim myConnection As New SqlConnection(ConnectionString)
> > * * * *Dim myCommand As New SqlCommand(strSP, myConnection)
> > * * * *myConnection.Open()
> > * * * *Dim strValue As String = myCommand.ExecuteScalar().ToString()
> > * * * *myConnection.Close()

>
> > * * * *Return strValue
> > End Function

>
> OK, then. Please try the following and tell me where it fails:
>
> Dim strGetValue As String
> strGetValue = Generic_database_functions.GetValue("SELECT
> ISNULL(Sum(Budget), 0) FROM vwPROJECTForecast")
> Dim decValue As Decimal
> decValue = Convert.ToDecimal(strGetValue)
> lblBudget.Text = decValue.ToString("#.##0")
>
> BTW, you should really put some exception handling in your function or, at
> the very least, use the Using syntax... As it stands, any error in the
> ExecuteScaler line is liable to leave your connection open...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net- Dölj citerad text -
>
> - Visa citerad text -


The problem is solved! Your code was completely correct and it was a
formula with additions containing the converted variables that caused
the error. Thank you for the help!

/ S
 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      01-10-2008
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On 10 Jan, 17:10, "Mark Rae [MVP]" <(E-Mail Removed)> wrote:

> The problem is solved! Your code was completely correct and it was a
> formula with additions containing the converted variables that caused
> the error. Thank you for the help!


Phew! Thought I was going crazy for a second...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dll config and web.config and Label Expressions (binding label text to dll config settings) CSharpner ASP .Net 0 04-09-2007 09:00 PM
<label><div></div></label> allowed? Josef K. ASP .Net 3 05-22-2005 02:13 PM
label versus asp:label Question. Thanks. Shapper ASP .Net 2 05-07-2005 05:55 AM
How to create a label which only displays a certain amount of characters? Daniel Walzenbach ASP .Net Web Controls 3 03-04-2004 09:49 AM
Efficient format for huge amount of data Gabriel Genellina Java 21 01-23-2004 10:56 PM



Advertisments