954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Formatting a label

I have a label that displays information from my database and I need to format it. It displays a number format like so: (53389) and I just need it to display (53,389)
it uses the SQL to COUNT or SUM the data from the datasource.

My first question is, is there a way to have it format like I want when it is displayed, or do I need to change the data format in the database?

here is my code:

Try
            Me.MAINTableAdapter.Fill(Me.MainDataSet.MAIN)
            Me.MAINTableAdapter1.FillByExceeds(Me.BurnListingDataSet.MAIN)
        Catch ex As Exception
        End Try

        Try
            Dim arx As Integer
            arx = MainDataSet.Tables("MAIN").Rows.Count
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT SUM(BurnSize) FROM MAIN", con)
            Dim cmd2 As OleDbCommand = New OleDbCommand("SELECT COUNT(BurnSize) FROM MAIN", con)
            con.Open()
            Try

                Dim acrestotal As Int32 = cmd.ExecuteScalar
                Dim burnscount As Int32 = cmd2.ExecuteScalar
                Label1.Text = "There are " & burnscount & " burns in the database for " & acrestotal & " total acres."

            Catch ex As Exception
                MsgBox("Error getting data!", MsgBoxStyle.Information, "Error...")
            End Try

            con.Close()
        Catch ex As Exception
        End Try


Label1.text is what I am wanting to format, both the variables.

msrd
Newbie Poster
13 posts since Aug 2009
Reputation Points: 10
Solved Threads: 1
 
Label1.Text = String.Format("There are {0:#,##0} burns in the database for {1:#,##0} total acres.", burnscount, acrestotal);


String.Format

Momerath
Nearly a Senior Poster
3,386 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: