473,466 Members | 1,451 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Format text in label to amount

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
Jan 9 '08 #1
7 4417
<st****@gmail.comwrote in message
news:54**********************************@d21g2000 prf.googlegroups.com...
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

Jan 9 '08 #2
On 9 Jan, 15:02, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<sta...@gmail.comwrote in message

news:54**********************************@d21g2000 prf.googlegroups.com...
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
Jan 10 '08 #3
<st****@gmail.comwrote in message
news:29**********************************@l1g2000h sa.googlegroups.com...
>lblBudget.Text =
Convert.ToDecimal(Generic_database_functions.GetV alue("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

Jan 10 '08 #4
On 10 Jan, 15:34, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<sta...@gmail.comwrote in message

news:29**********************************@l1g2000h sa.googlegroups.com...
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
Jan 10 '08 #5
<st****@gmail.comwrote in message
news:8c**********************************@s8g2000p rg.googlegroups.com...
On 10 Jan, 15:34, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
><sta...@gmail.comwrote in message

news:29**********************************@l1g2000 hsa.googlegroups.com...
>lblBudget.Text =
Convert.ToDecimal(Generic_database_functions.GetV alue("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

Jan 10 '08 #6
On 10 Jan, 17:10, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<sta...@gmail.comwrote in message

news:8c**********************************@s8g2000p rg.googlegroups.com...


On 10 Jan, 15:34, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
<sta...@gmail.comwrote in message
>news:29**********************************@l1g2000 hsa.googlegroups.com...
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
Jan 10 '08 #7
<st****@gmail.comwrote in message
news:36**********************************@21g2000h sj.googlegroups.com...
On 10 Jan, 17:10, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
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

Jan 10 '08 #8

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

Similar topics

1
by: Newgene | last post by:
Hi, group, I have python2.3 installed on win2k. I noticed that when I open a dos format text file (eol is '\r\n'), readline() always returns a line ending with '\n' only, not '\r\n'. While I read...
2
by: FrodoBaggins | last post by:
Dear Team, I am trying to use stylesheets on a web form. Initially, I created a folder named 'styles' within the WebUI project. In this I created the following stylesheet named...
2
by: ezelasky | last post by:
We are using the bcp utility (via APIs) to export data from a SQL table in a fixed format text file. BCP is inserting spaces for a field if the field contains a NULL. This is fine with us except...
2
by: Hareth | last post by:
i got the idea "form.textbox.text = label.text" from vb... i tried it in C# but it generated errors i found a diff example from :...
3
by: dennist685 | last post by:
Format text as a heading I'm progressing through a walkthrough on DetailsView control Early on it says Type Edit Employees, select the text, and then format the text as a heading. I clicked...
13
by: Neil Cerutti | last post by:
Many of the file formats I have to work with are so-called fixed-format records, where every line in the file is a record, and every field in a record takes up a specific amount of space. For...
5
by: Yohan Blurp | last post by:
Hi, Here is sample page to show you the problem : <html><body> <form action="/cgi-bin/test.cgi" method="post"> Data Path : <input type="text" size="50" value="C:\Test Data\May 2007.xls"...
3
by: bhanubalaji | last post by:
hi, I am unable to disable the text(label) in javascript..it's working fine with IE,but i am using MOZILLA.. can any one help regarding this.. What's the wrong with my code? I am...
2
damonreid
by: damonreid | last post by:
Is it possible to pass a field to a text label when a form loads? I have tried Private Sub Form_Load() Dim textName As String textName = "Text Edit Text" Me.Text29 =...
1
by: kenneth6 | last post by:
Windows form app: 1. how to get text label updated? 2. how to get text label assigned with a variable value (integer / string)?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.