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. Need help with datatable

Need help with datatable

Scheduled Pinned Locked Moved C#
help
6 Posts 3 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.
  • S Offline
    S Offline
    superselector
    wrote on last edited by
    #1

    Hi i have a datatable having columns Col1 and Col2 Col1 Col2 A,B,C,D P,Q,R I want to get the final output in datatable as Col1 Col2 A P B Q C R D The first datatable will always have one row but the number of columns will vary . The final datatable should be exact replica of first datatable but the column values in first datatable separated by comma should be displayed as a row in final table. Please help.

    G R 2 Replies Last reply
    0
    • S superselector

      Hi i have a datatable having columns Col1 and Col2 Col1 Col2 A,B,C,D P,Q,R I want to get the final output in datatable as Col1 Col2 A P B Q C R D The first datatable will always have one row but the number of columns will vary . The final datatable should be exact replica of first datatable but the column values in first datatable separated by comma should be displayed as a row in final table. Please help.

      G Offline
      G Offline
      Gergo Bogdan
      wrote on last edited by
      #2

      Is there a way to identify how many items does the first column have? I can see that the P, Q, R values are for the second column, how would you know where to start splitting?

      superselector wrote:

      Col1 Col2 A P B Q C R D

      S 1 Reply Last reply
      0
      • G Gergo Bogdan

        Is there a way to identify how many items does the first column have? I can see that the P, Q, R values are for the second column, how would you know where to start splitting?

        superselector wrote:

        Col1 Col2 A P B Q C R D

        S Offline
        S Offline
        superselector
        wrote on last edited by
        #3

        The number of items may vary in a culumn.. but one thing is consistent that values will be seperated by comma,its just a sample i have given for understanding of the question. also the number of columns in first datatable is dynamic. it will change based on certain condition but irrespective of the number of columns i want to replicate this datatable and display those comma separated values in a row. The final datatable should have as many rows as the highest lenght of the splitted value

        G 1 Reply Last reply
        0
        • S superselector

          The number of items may vary in a culumn.. but one thing is consistent that values will be seperated by comma,its just a sample i have given for understanding of the question. also the number of columns in first datatable is dynamic. it will change based on certain condition but irrespective of the number of columns i want to replicate this datatable and display those comma separated values in a row. The final datatable should have as many rows as the highest lenght of the splitted value

          G Offline
          G Offline
          Gergo Bogdan
          wrote on last edited by
          #4

          OK, maybe I was not clear, lets have this example: DataTable 1: Column1, Column2, Column3 DataTable 2: Value1, Value2, Value3, Value4, Value5, Value6, Value7, Value8 The final result for you should be like below?

          Column1, Column2, Column3
          Value1, Value2, Value3
          Value4, Value5, Value6
          Value7, Value8

          if the above representation is OK, its quite simple, you just have to: 1. Add to the new DataTable the content of the first DataTable 2. Add a new row to the new DataTable, start to add the values 3. When you reached the length of the first DataTable (or first row of the current DataTable) you need to start a new row.

          S 1 Reply Last reply
          0
          • G Gergo Bogdan

            OK, maybe I was not clear, lets have this example: DataTable 1: Column1, Column2, Column3 DataTable 2: Value1, Value2, Value3, Value4, Value5, Value6, Value7, Value8 The final result for you should be like below?

            Column1, Column2, Column3
            Value1, Value2, Value3
            Value4, Value5, Value6
            Value7, Value8

            if the above representation is OK, its quite simple, you just have to: 1. Add to the new DataTable the content of the first DataTable 2. Add a new row to the new DataTable, start to add the values 3. When you reached the length of the first DataTable (or first row of the current DataTable) you need to start a new row.

            S Offline
            S Offline
            superselector
            wrote on last edited by
            #5

            Thanks , I was able to get it working.

            1 Reply Last reply
            0
            • S superselector

              Hi i have a datatable having columns Col1 and Col2 Col1 Col2 A,B,C,D P,Q,R I want to get the final output in datatable as Col1 Col2 A P B Q C R D The first datatable will always have one row but the number of columns will vary . The final datatable should be exact replica of first datatable but the column values in first datatable separated by comma should be displayed as a row in final table. Please help.

              R Offline
              R Offline
              Ron Nicholson
              wrote on last edited by
              #6

              Ok, if I am understanding correctly, I would approach it like this. Loop through each column Convert the data from that column to a 'table' - I do this with some SSRS reports. There are a lot of links about doing this example 1, example 2. I would try putting each into it's own table then combining them in the end, but it seems like there should be an easier way.

              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