DataColumn.Expression formatting

  • Thread starter Thread starter magne
  • Start date Start date
M

magne

I need a calulated field which formats an integer (another column in the
same row) to a certain number of digits (leading zeroes).
How to specify the DataColumn.Expression property for this ?
 
The DataColumn.Expression doesn't support formating, sorry.

You can write an event handler for the DataTable.ColumnChanged or
DataTable.RowChanged events and "manually" maintain the formated field.
 
Hi Magne,

Thank you for posting.

There is an example of formatting an integer to a five number of digits
string(if the digit number of the integer is bigger than five, the
formatted string is equal to the integer).

The data type of the "Quantity" column in my DataTable is System.Int32 and
that of the "FormatQuantity" column is System.String.

dataSet11.Tables[0].Columns["FormatQuantity"].Expression =
"IIF(Len(Convert(Quantity,'System.String')) >= 5,Quantity,
SubString('00000' + Quantity, Len(convert(Quantity,'System.String')) +
1,5))";

Hope this helps.
If you have any concerns or need anything else, please don't hesitate to
let me know.


Sincerely,
Linda Liu
Microsoft Online Community Support

====================================================
When responding to posts,please "Reply to Group" via
your newsreader so that others may learn and benefit
from your issue.
====================================================
 
Back
Top