Formatting currency for a label

Hi I am trying to get the subtotal query to show as a #.## value. Now I am getting four digits to the right of the decimal. I have tried various permutations of below, but I get either an error or no change.
void CalcTotal()
        //declare and initialize connection object to connect to the database
        SqlConnection conn = new SqlConnection(
        SqlCommand cmd; //declare a command object that will be used to send commands to database.
        cmd = conn.CreateCommand();

        cmd.CommandText = "Select Sum(Quantity*Listprice) " +
            "From Shopcartline as SHL inner join Song as S on SHL.SongID = S.SongID " +
            "Where ShopcartID = " + Session["shopCartID"];
        cmd.CommandType = CommandType.Text;

        //declare an SqlDataReader variable
        SqlDataReader dataReader;
        dataReader = cmd.ExecuteReader();

        if (dataReader.HasRows)
            lblTotal.Text = dataReader.GetValue(0).ToString();
          lblTotal.Text = String.Format("{0:C2}",lblTotal.Text);<----Here
            lblTotal.Text = "";

Open in new window

Who is Participating?
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.

Alfred A.Commented:

Try this,

lblTotal.Text = lblTotal.Text.ToString("f2")
Alfred A.Commented:

Or, you can try this if you are formatting currency,

lblTotal.Text = lblTotal.Text.ToString("C2")
Om PrakashCommented:

string a = dataReader.GetValue(0).ToString();
lblTotal.Text = a.ToString("#0.00"));
Try this:

Double amount =(Double) dataReader.GetValue(0);
lblTotal.Text = amount.ToString("c2");

string amount = dataReader.GetValue(0).ToString();
lblTotal.Text = Convert.ToDouble(amount).ToString("c2");<----Here
I think that will be enough:
lblTotal.Text =String.Format("{0:C2}", dataReader.GetValue(0));

Open in new window


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
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

From novice to tech pro — start learning today.