It doesn't work.
The context is DataColumn.Expression syntax. What you said is C# syntax and
you cannot use it in DataColumn.Expression realm.
Regards,
Alan
Hi
Are you running a ASP.NET or winforms application?
Are you using a Datagrid?
Based on my research, here is some code about how to do that in a Grid view
in winform.
1. Set current thread's date pattern to "yyyy-MM-dd"
[STAThread]
static void Main()
{
CultureInfo ci =
(CultureInfo)CultureInfo.CurrentCulture.Clone();
ci.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
Thread.CurrentThread.CurrentCulture = ci;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
2. For the string as "Date: xxxx-xx-xx"
private void Form1_Load(object sender, EventArgs e)
{
DataTable table = new DataTable();
//// Create the first column.
DataColumn dateColumn = new DataColumn();
dateColumn.DataType = System.Type.GetType("System.DateTime");
dateColumn.ColumnName = "date";
dateColumn.DefaultValue = "2002-4-18";
//// Create the second, calculated, column.
DataColumn testColumn = new DataColumn();
testColumn.DataType = System.Type.GetType("System.String");
testColumn.ColumnName = "Test";
testColumn.Expression = "'Date: ' + SubString(Convert(date,
'System.String'),1,10)";
// Add columns to DataTable.
table.Columns.Add(dateColumn);
table.Columns.Add(testColumn);
DataRow row = table.NewRow();
table.Rows.Add(row);
DataView view = new DataView(table);
this.dataGridView1.DataSource = view;
}
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
A.M-SG - 30 Jan 2006 15:37 GMT
It is a winforms application. I like to set it up at the datatable level.
If it is not possible, then I have to do some custom code work.
In your example you changed the formatting behaviour globally. I cannot do
that.
Thank you for help.
Alan
> Hi
>
[quoted text clipped - 53 lines]
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
"Peter Huang" [MSFT] - 31 Jan 2006 06:55 GMT
Hi Alan,
The expression is ususally used to do the mathematical or string operation,
it did not have many string format feature.
In the whole application view, the datatable should be in the data layer,
the string format should be taken care in the presentation layer.
e.g. the Winform DataGrid,GridView.......
Best regards,
Peter Huang
Microsoft Online Partner Support

Signature
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.