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. Visual Basic
  4. How to split one dataset into two datatable???

How to split one dataset into two datatable???

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
5 Posts 4 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
    star_platinum
    wrote on last edited by
    #1

    Hi All, I have created a dataset which contains 50 records. I want to put the first 20 records in one datatable and the last 30 records into another datatable. I don't know how to do it. anyone has idea? Thanks Tin

    D 1 Reply Last reply
    0
    • S star_platinum

      Hi All, I have created a dataset which contains 50 records. I want to put the first 20 records in one datatable and the last 30 records into another datatable. I don't know how to do it. anyone has idea? Thanks Tin

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      tinmail wrote:

      I have created a dataset which contains 50 records.

      Not true. A DataSet is a collection of DataTable objects, which are collections of DataRow objects. You have a DataSet, then contains a DataTable, which contains 50 records. Are these 50 records generated by your code, or are they retrieved from a database?? If retrieved, the problem would be solved by running two queries against the database and have it dump each set on records into seperate DataTable objects. If generated, then it's easier to put the records in the correct table when they are generated, not after.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        tinmail wrote:

        I have created a dataset which contains 50 records.

        Not true. A DataSet is a collection of DataTable objects, which are collections of DataRow objects. You have a DataSet, then contains a DataTable, which contains 50 records. Are these 50 records generated by your code, or are they retrieved from a database?? If retrieved, the problem would be solved by running two queries against the database and have it dump each set on records into seperate DataTable objects. If generated, then it's easier to put the records in the correct table when they are generated, not after.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

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

        Thanks for your reply, Dave. The dataset is retrieved from database. What I am trying to do is select the Top 50 records in database then show the top 20 into a datalist and the rest in another datalist. I know in SQL server doesn't have the "LIMIT" function. Thats why I don't know how to get those 30 records. Thanks Tin

        M J 2 Replies Last reply
        0
        • S star_platinum

          Thanks for your reply, Dave. The dataset is retrieved from database. What I am trying to do is select the Top 50 records in database then show the top 20 into a datalist and the rest in another datalist. I know in SQL server doesn't have the "LIMIT" function. Thats why I don't know how to get those 30 records. Thanks Tin

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          2 easy options. 1 use a dataview for each datalist (not a control I know of) applying an appropriate rowfilter. 2 use the same rowfilters and user copytotable on the filtered dataview, then use the seperate tables for the datalist. 3rd one user linq to filter the datatable binding the resultset to the datalist - I seperate this as I have limited experience with linq.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • S star_platinum

            Thanks for your reply, Dave. The dataset is retrieved from database. What I am trying to do is select the Top 50 records in database then show the top 20 into a datalist and the rest in another datalist. I know in SQL server doesn't have the "LIMIT" function. Thats why I don't know how to get those 30 records. Thanks Tin

            J Offline
            J Offline
            Jon_Boy
            wrote on last edited by
            #5

            tinmail wrote:

            I know in SQL server doesn't have the "LIMIT" function.

            Not really true. You could create your dataset with 2 tables (like Dave referred to earlier): DataSet Orders Table (top 20 customers) Table2 (bottom 30 customers). You would then use a 'Select TOP' and an ORDER BY statement to order the records however you want (maybe combined with a group by) and do the fills. Top 20 highest Select top 20 * From Customers order by AR Balance Bottom 30 Select top 30 * From Customers order by AR Balance desc Personally, I would just fill one datatable and use a dataview to filter the rows vs filling two tables.

            Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

            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