473,472 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

formatting DataColumn.Expression

J
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how about
simply displaying the column formatted as a number with only 2 decimals
(#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )"; //error
: Expression does not support String.Format
Nov 15 '05 #1
3 18637
Hi,

I think the burden of formatting should be put on a presentation tier code
(e.g. the DataGrid control) and not on a DataColumn - it's just not made to
be formattable by itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vn************@corp.supernews.com...
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how about simply displaying the column formatted as a number with only 2 decimals
(#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )"; //error : Expression does not support String.Format


Nov 15 '05 #2
J
The example was formatting as currency, but the principal applies to
unlimited situations.
Don't think of it as formatting for the presentation layer, think of it as
building calculated datacolumns that require use of procedures, functions,
classes, whatever. To build any kind of calculated datacolumn, except for
the most simple, requires this functionality.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
Hi,

I think the burden of formatting should be put on a presentation tier code
(e.g. the DataGrid control) and not on a DataColumn - it's just not made to be formattable by itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vn************@corp.supernews.com...
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how

about
simply displaying the column formatted as a number with only 2 decimals
(#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )";

//error
: Expression does not support String.Format

Nov 15 '05 #3
This seem to be limited by the allowed syntax in the Expression property
(please refer to the "DataColumn.Expression Property" topic in MSDN), which
resembles SQL and has no support for calling managed code.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vo************@corp.supernews.com...
The example was formatting as currency, but the principal applies to
unlimited situations.
Don't think of it as formatting for the presentation layer, think of it as
building calculated datacolumns that require use of procedures, functions,
classes, whatever. To build any kind of calculated datacolumn, except for the most simple, requires this functionality.

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:Ot**************@TK2MSFTNGP11.phx.gbl...
Hi,

I think the burden of formatting should be put on a presentation tier code (e.g. the DataGrid control) and not on a DataColumn - it's just not made

to
be formattable by itself.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"J" <j> wrote in message news:vn************@corp.supernews.com...
Is there anyway to format a calculated datacolumn? I would like the
following column to display as money (formatted as $#,##0.00). Or how

about
simply displaying the column formatted as a number with only 2 decimals (#,##0.00)?
In the sample below, amount and taxrate are existing DataColumn's.

DataColumn colTax = new DataColumn();
colTax.DataType = System.Type.GetType("System.String");
colTax.ColumnName = "tax";
myTable.Columns.Add(colTax);
colTax.Expression = "String.Format(\"{0:C}\",\"amount*taxrate\" )";

//error
: Expression does not support String.Format



Nov 15 '05 #4

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

Similar topics

0
by: J | last post by:
Is there anyway to format a calculated datacolumn? I would like the following column to display as money (formatted as $#,##0.00). Or how about simply displaying the column formatted as a number...
1
by: Rui Rosa Mendes | last post by:
I need a Round function, in Expression Syntax. - Is there any not documented? - Can I associate one? Thanks. Rui rrm@medialog.pt
1
by: Dde | last post by:
Hi everybody, I have a problem with the "IN" operator in a datacolumn expression. I have a datatable on which the following expression works: mycode = '05' but the following does not work:...
1
by: Vai2000 | last post by:
Hi All, I have a dataColumn type of string which has values in form of range like 0-80 or sometimes just 1 value like 100. I want to add another column which basically computes the count of the...
1
by: Jason | last post by:
First off, I tried to find an ADO.NET forum, or even just a .NET framework forum but couldn't seem to locate one and I apologize in advance if I've posted in the wrong place. Because I'm using a...
11
by: Matt F | last post by:
I'm trying to do something that seems like it should be pretty simple, but haven't found a solution. I am trying to add a datacolumn to a datatable that adds or subtracts a number of days based on...
3
by: shark | last post by:
Hi Is it any way to use current column value in Expression for this column. Let say we want to have: DataColumn2.Expression = IIF(DataColumn1 <0, DataColumn1, DataColumn2) Its'n valid but how...
0
by: SMH | last post by:
Hi All, I am currently learning .Net 2, studying for 70-528. I've hit a bit of a brick wall with DataColumn.Expression. As I understand it, this can be used to (For example) concatenate two...
1
by: jelling | last post by:
Hi, Is it possible to use a CASE or IF ELSE statement in a datacolumn expression? Here's what I've tried: 'standardCodeColumn.Expression = "CASE StandardsBodyID WHEN 1 THEN 'JCAHO' ELSE...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.