Click to See Complete Forum and Search --> : How to split a datatable?


mic.strange
February 27th, 2009, 12:19 AM
Hi all,


I need to split a SELECT QUERY fom a database (which i put in a DataTable) from this:

DataTable1
0
1
2
3
4
5
6
7
8
9
10
0
1
2
3
4
5
6
7
8
9
10
0
1
2
3
0
1
2
0
1

To this:

DataTable1
0
1
2
3
4
5
6
7
8
9
10

DataTable2
0
1
2
3
4
5
6
7
8
9
10

DataTable3
0
1
2
3

DataTable4
0
1
2

DataTable5
0
1

How can i do that??

Shuja Ali
February 27th, 2009, 01:16 AM
What is the logic behind splitting it. Maybe you can elaborate why Datatable5 would only contain 0 & 1. Also why not do this at the database level when you are writing the select query.

mic.strange
February 27th, 2009, 01:19 AM
I need it for a graph-plotting class.

Therefore i need to split it to get multiple lines/bars.

Each line/bar in the class needs a DataTable to retrieve data.

Shuja Ali
February 27th, 2009, 01:27 AM
My question was, how would you identify where exactly the DataTable needs to be split. If you can give a real life example rather than the one that you have posted above, it will help us in suggesting something better.

mic.strange
February 27th, 2009, 01:35 AM
I wil try my best :)


I need it to split the data everytime the value is = 0.

That way i can split one graph-line into multiple lines instead of one long line af data.

Please look at the attachement.

I hopes it makes sense.

Shuja Ali
February 27th, 2009, 01:45 AM
One of the ways to do it is to loop through each row and once a row with 0 is found, copy it over to a new datatable. There is no internal method in the datatable that you can use to split it.