27
Using Expressions in DataTable DataColumn
Using Expressions in DataTable DataColumn :
Do you know :
How to use expression in datatable datacolumn
?
The expression syntax available is used to create customize columns, it is probably much richer than you might think. Expression Property of the DataColumn
Dynamically changing DataTable Column Value using Expressions.
private void CalcColumns()
{
DataTable table = new DataTable ();
// Create the first column.
DataColumn priceColumn = new DataColumn();
priceColumn.DataType = System.Type.GetType(”System.Decimal”);
priceColumn.ColumnName = “price”;
priceColumn.DefaultValue = 50;
// Create the second, calculated, column.
DataColumn taxColumn = new DataColumn();
taxColumn.DataType = System.Type.GetType(”System.Decimal”);
taxColumn.ColumnName = “tax”;
taxColumn.Expression = “price * 0.0862″;
// Create third column.
DataColumn totalColumn = new DataColumn();
totalColumn.DataType = System.Type.GetType(”System.Decimal”);
totalColumn.ColumnName = “total”;
totalColumn.Expression = “price + tax”;
// Add columns to DataTable.
table.Columns.Add(priceColumn);
table.Columns.Add(taxColumn);
table.Columns.Add(totalColumn);
DataRow row = table.NewRow();
table.Rows.Add(row);
DataView view = new DataView(table);
dataGrid1.DataSource = view;
}
For more example :
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(vs.71).aspx
http://davidhayden.com/blog/dave/archive/2006/07/09/DataColumnExpressions.aspx
There are no comments.