Need help with datatable
-
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.
-
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.
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
-
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
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
-
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
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, Value8if 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.
-
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, Value8if 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.
Thanks , I was able to get it working.
-
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.
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.