How to add dynamic column of pivot sql server in web api controller for .net
-
Anyone know how can I add dynamic column based on the pivot table in the controller? As I search most of the answer is for mvc so I do not have any idea on how to add dynamic column for my situation. The user will able to multiselect the company code to get the report result. The CompanyCode should refer to the dynamic column [12-MD/AL,3-EP/AE,7-SV], how can I get the dynamic column for company code? My result from database to datatable in controller Datatable return from the database in pivot for three company selected : Image 1 Datatable return from the database in pivot for two company selected : Image 2 ReportController.cs
DataTable dt = bl_API.REPORT_DETAIL(); // success return datatable from stored procedure
foreach(DataRow dr in dt.Rows) {
o_GetDetail = new oGetReportDetail();
o_GetDetail.ConsolCode = dr["MCI_CODE"].ToString();
o_GetDetail.ConsolDesc = dr["MCI_DESC"].ToString();
o_GetDetail.ConsolSeq = dr["MCI_SEQ"].ToString();
o_GetDetail.RootType = dr["MAR_NAME_EN"].ToString();Row.Add(o_GetDetail);
}
res.Records = Row;
return res;
//res that I get
[0] CompanyCode = "", ConsolCode = "PPE", ConsolDesc = "PROPERTY, PLANT & EQUIPMENTS", RootType = "NON CURRENT ASSETS", ConsolSeq = "1"
[1] CompanyCode = "", ConsolCode = "LPD", ConsolDesc = "LAND & PROPERTY DEVELOPMENT COSTS", RootType = "NON CURRENT ASSETS", ConsolSeq = "2"
and so onoGetReportDetail.cs
public class oGetReportDetail
{
public oGetReportDetail()
{
CompanyCode = "";
ConsolCode = "";
ConsolDesc = "";
ConsolSeq = "";
RootType = "";} public string CompanyCode { get; set; } public string ConsolCode { get; set; } public string ConsolDesc { get; set; } public string ConsolSeq { get; set; } public string RootType { get; set; } }