Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. How to add dynamic column of pivot sql server in web api controller for .net

How to add dynamic column of pivot sql server in web api controller for .net

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasequestioncsharpasp-netsql-server
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    esther123
    wrote on last edited by
    #1

    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 on

    oGetReportDetail.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; }
    
    }
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups