Wednesday, December 16, 2015

How to calculated data columns to DataTable c#


DataTable table = new DataTable("Purchase Items");

DataColumn workCol = table .Columns.Add("ID", typeof(Int32));
table .Columns.Add("UnitPrice", typeof(Double));
table .Columns.Add("Qty", typeof(Int32));
table .Columns.Add("Total", typeof(Double));
table .Columns.Add("Discount", typeof(Double));

table .Columns["Total"].Expression = "UnitPrice*Quantity";
table .Columns["Discount"].Expression = String.Format("Total*{0}",Discount);

grdData.DataSource = table ;
grdData.Update();

No comments:

Post a Comment