I am using C# winforms to create an application that needs to turn a datatable into a pivot table. I have the pivot table working fine from a SQL end, but creating it from a da
Another small piece of code to pivot any table you would want:
var dataTable = new DataTable(); // your input DataTable here!
var pivotedDataTable = new DataTable(); //the pivoted result
var firstColumnName = "Year";
var pivotColumnName = "Codes";
pivotedDataTable.Columns.Add(firstColumnName);
pivotedDataTable.Columns.AddRange(
dataTable.Rows.Cast().Select(x => new DataColumn(x[pivotColumnName].ToString())).ToArray());
for (var index = 1; index < dataTable.Columns.Count; index++)
{
pivotedDataTable.Rows.Add(
new List