datatable don't show the formatted value

Posted on 2010-01-13
Medium Priority
Last Modified: 2012-05-08
In ASP.NET 1.1 with C# I have a datatable.
one of the columns is Decimal.
I put in this cell a value which I collected
for example I got the value    26423874
I format this value to a string value and get the value  26,423,874.00
when I put this value in the datatable I get 26423874
Why is that?

part of the code:

DataTable dtableShow = new DataTable();
DataRow row = null;
decimal sumTotalBalanceDec = 0;
dtableShow ("totalBalance",typeof(Decimal));
row = dtableShow.NewRow();
object sumTotalBalance =  dtcollect.Compute("SUM(TotalBalance)",filter);
//  sumTotalBalance  = 26423874
sumTotalBalanceDec = Convert.ToDecimal(sumTotalBalance);
string titleImg = sumTotalBalanceDec.ToString("#,###0.00");
//  titleImg  = 26,423,874.00
row["totalBalance"] = titleImg;  //  = 26423874
Question by:ANAT2403
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4

Author Comment

ID: 26301933
sorry, I had a mistake in one line in the kod:
dtableShow ("totalBalance",typeof(Decimal));
should be
dtableShow .Columns.Add("totalBalance",typeof(Decimal));

Author Comment

ID: 26302474
No body answer my qusetion??????????
I am expecting some treatment .................
LVL 10

Expert Comment

ID: 26309231
Do you want to keep the format in DataTable?

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 10

Expert Comment

ID: 26309259
FYI, if after certain hours there is still nobody answering your question, the EE system will automatically send out an alert to some designated experts asking them to attend to your question.

You may also know that experts answering questions here are volunteers.

Author Comment

ID: 26311533
Hi codingbeaver
(Sorry I was a bit pressed and I needed a solution quickly, but I managed.)
yes I do want to keep the format in datatable and then I want to use the compute.
I did something now that solved my problems but still I have qustion.
In order to see the format, I canceled  the type of the column from decimal, and I guess now it is string.
Now I can see the format cell but I can't use the compute because it is not a numeric cell so I used
for each....
Is it possible to use compute on a non numeric column?
LVL 10

Expert Comment

ID: 26314205
I don't thnk so, and I am open for correction.

If I were you, I would like to keep the data type as numeric in database, because I could format it anyway I want in the future. But for string with format, take your case as example, 26,423,874.00, when you want to convert it to numeric, you will first have to remove the "," in the string, then you can parse it to a numeric value. Can I ask why you need to store the formatted string in your database instead of numeric?

Author Comment

ID: 26320908
I don't keep any of this inormation in my database
I get the information from an xml file
(by the way I am force to work with dot net 1.1)
I trasfer it to a collection in a first datatable
then I prepare a second formatted datatable that in the end I bind to a datagrid.
I wanted to summarize the values in the second datatable.
I already solved my problem by using the foreach command but I wanted to know
on what types I can use the compute function
LVL 10

Accepted Solution

codingbeaver earned 2000 total points
ID: 26323339
That's good you got it solved.

I believe you have to have numeric data type to use compute, and I am open for correction.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 12 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question