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. C#
  4. Pivot table in .net

Pivot table in .net

Scheduled Pinned Locked Moved C#
csharphelptutorial
3 Posts 2 Posters 0 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.
  • P Offline
    P Offline
    Prabhakar A
    wrote on last edited by
    #1

    Hi all, Anyone knows how to use pivot table in .net(c#) It works well in vb but it is not working in .net . since i am new to this type of concepts .Help me:~ Prabhakar.A Software Engineer

    R 1 Reply Last reply
    0
    • P Prabhakar A

      Hi all, Anyone knows how to use pivot table in .net(c#) It works well in vb but it is not working in .net . since i am new to this type of concepts .Help me:~ Prabhakar.A Software Engineer

      R Offline
      R Offline
      Ravindra Sadaphule
      wrote on last edited by
      #2

      Let’s say we have a product table where each row represents product details like product Id, Name, Description , Price etc. Now customer might be interested to view products across (i.e. columns) and features down (row wise). This basically requires transposing product table’s rows and columns as illustrated below. The first step is to create the new Data Table and its schema from the rows of the input table. In the following code snippet, source refers to the input table and dest is the new pivoted table. //Create Destination Table DataTable dest = new DataTable("Pivot" ); // from each source table row (1st column) // create a destination column foreach( DataRow r in source.Rows ) dest.Columns.Add( r[0].ToString() ); // assign each row the Product name Now that we have the appropriate columns defined in the schema of the destination table, the next step is to create a DataRow for each feature defined in the columns of the source table, excluding the first column representing the Product name. //Create columns in destination table for each row in source table. for( int i = 0; i < source.Columns.Count - 1; i++ ) dest.Rows.Add( dest.NewRow() ); The final step is the actual transform of the columns from the source rows into the destination table. Since each table now represents a two dimensional array of its rows and columns, a very simple transform of all columns and rows could be performed by the following nested for loop. //Transpose rows and columns for( int r = 0; r < dest.Rows.Count; r++ ) for( int c = 0; c < source.Columns.Count; c++ ) dest.Rows[r][c] = source.Rows[c][r]; Ravindra Sadaphule MCSD.NET

      P 1 Reply Last reply
      0
      • R Ravindra Sadaphule

        Let’s say we have a product table where each row represents product details like product Id, Name, Description , Price etc. Now customer might be interested to view products across (i.e. columns) and features down (row wise). This basically requires transposing product table’s rows and columns as illustrated below. The first step is to create the new Data Table and its schema from the rows of the input table. In the following code snippet, source refers to the input table and dest is the new pivoted table. //Create Destination Table DataTable dest = new DataTable("Pivot" ); // from each source table row (1st column) // create a destination column foreach( DataRow r in source.Rows ) dest.Columns.Add( r[0].ToString() ); // assign each row the Product name Now that we have the appropriate columns defined in the schema of the destination table, the next step is to create a DataRow for each feature defined in the columns of the source table, excluding the first column representing the Product name. //Create columns in destination table for each row in source table. for( int i = 0; i < source.Columns.Count - 1; i++ ) dest.Rows.Add( dest.NewRow() ); The final step is the actual transform of the columns from the source rows into the destination table. Since each table now represents a two dimensional array of its rows and columns, a very simple transform of all columns and rows could be performed by the following nested for loop. //Transpose rows and columns for( int r = 0; r < dest.Rows.Count; r++ ) for( int c = 0; c < source.Columns.Count; c++ ) dest.Rows[r][c] = source.Rows[c][r]; Ravindra Sadaphule MCSD.NET

        P Offline
        P Offline
        Prabhakar A
        wrote on last edited by
        #3

        Thanx, But I am asking Microsoft Office Pivot Table 9.0 component in asp.net :confused: Prabhakar.A Software Engineer

        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