CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2009
    Posts
    3

    Talking How to split a datatable?

    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??

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: How to split a datatable?

    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.

  3. #3
    Join Date
    Feb 2009
    Posts
    3

    Re: How to split a datatable?

    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.

  4. #4
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: How to split a datatable?

    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.

  5. #5
    Join Date
    Feb 2009
    Posts
    3

    Re: How to split a datatable?

    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.
    Attached Images Attached Images

  6. #6
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: How to split a datatable?

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured