Add calculated data columns to datatable c#

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

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

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

dataGridView1.DataSource = workTable;
dataGridView1.Update();

Comments

Popular posts from this blog

This content database has a schema version which is not supported in this farm

Export all documents/Folders permissions to CSV using SharePoint PowerShell

SPUtility.js