ANAT2403
asked on
datatable don't show the formatted value
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(Dec imal));
row = dtableShow.NewRow();
object sumTotalBalance = dtcollect.Compute("SUM(Tot alBalance) ",filter);
// sumTotalBalance = 26423874
sumTotalBalanceDec = Convert.ToDecimal(sumTotal Balance);
string titleImg = sumTotalBalanceDec.ToStrin g("#,###0. 00");
// titleImg = 26,423,874.00
row["totalBalance"] = titleImg; // = 26423874
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(Dec
row = dtableShow.NewRow();
object sumTotalBalance = dtcollect.Compute("SUM(Tot
// sumTotalBalance = 26423874
sumTotalBalanceDec = Convert.ToDecimal(sumTotal
string titleImg = sumTotalBalanceDec.ToStrin
// titleImg = 26,423,874.00
row["totalBalance"] = titleImg; // = 26423874
ASKER
No body answer my qusetion??????????
I am expecting some treatment .................
thankyou
Anat
I am expecting some treatment .................
thankyou
Anat
Do you want to keep the format in DataTable?
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.
You may also know that experts answering questions here are volunteers.
ASKER
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?
Thankyou
Anat
(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?
Thankyou
Anat
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?
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?
ASKER
Hi
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
thankyou
Anat
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
thankyou
Anat
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dtableShow ("totalBalance",typeof(Dec
should be
dtableShow .Columns.Add("totalBalance
Anat