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. How to get first N rows from a datatable

How to get first N rows from a datatable

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 3 Posters 16 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.
  • P Offline
    P Offline
    panyl
    wrote on last edited by
    #1

    There is a method called datatable.select(string) to filter rows from a datatalbe But the string must contains one columnname in the datatable.I know nothing about the datatable,what i want to get is just the first N rows in the datatable. what should i do? Thanks

    N E 2 Replies Last reply
    0
    • P panyl

      There is a method called datatable.select(string) to filter rows from a datatalbe But the string must contains one columnname in the datatable.I know nothing about the datatable,what i want to get is just the first N rows in the datatable. what should i do? Thanks

      N Offline
      N Offline
      Nirandas
      wrote on last edited by
      #2

      The DataTable's Rows property contains all the rows in the table. Just loop through it.

      Nirandas, a developer from India. http://www.nirandas.com

      1 Reply Last reply
      0
      • P panyl

        There is a method called datatable.select(string) to filter rows from a datatalbe But the string must contains one columnname in the datatable.I know nothing about the datatable,what i want to get is just the first N rows in the datatable. what should i do? Thanks

        E Offline
        E Offline
        enginco
        wrote on last edited by
        #3

        IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Take(3);

        Now, you have a new DataRow list :)

        modified on Wednesday, July 16, 2008 7:06 AM

        P 1 Reply Last reply
        0
        • E enginco

          IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Take(3);

          Now, you have a new DataRow list :)

          modified on Wednesday, July 16, 2008 7:06 AM

          P Offline
          P Offline
          panyl
          wrote on last edited by
          #4

          thanks,thank you very much! accrooding your way i have solve my question.I could get the first 100Rows, But another question is how do i get the second 100 rows(101-200)? because i want to display 100rows/page. thanks for any help.

          E 1 Reply Last reply
          0
          • P panyl

            thanks,thank you very much! accrooding your way i have solve my question.I could get the first 100Rows, But another question is how do i get the second 100 rows(101-200)? because i want to display 100rows/page. thanks for any help.

            E Offline
            E Offline
            enginco
            wrote on last edited by
            #5

            if you thing to make paging you can use this: Maybe it's a bit long way but I couldn't find another way. for first 100 records: IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Take(100); for next n * 100 IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Skip(n * 100); I meant if someone clicked 5. page n=5 IEnumerable<DataRow> dt1 = myDataTable.AsEnumerable().Skip(n * 100); than you need new table with your new rows (dt1) your secondTable = dt1 after that again IEnumerable<DataRow> dt2 = secondTable.AsEnumerable().Take(100); I hope it's helpfull

            modified on Friday, July 25, 2008 8:31 AM

            P 1 Reply Last reply
            0
            • E enginco

              if you thing to make paging you can use this: Maybe it's a bit long way but I couldn't find another way. for first 100 records: IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Take(100); for next n * 100 IEnumerable<DataRow> dt = myDataTable.AsEnumerable().Skip(n * 100); I meant if someone clicked 5. page n=5 IEnumerable<DataRow> dt1 = myDataTable.AsEnumerable().Skip(n * 100); than you need new table with your new rows (dt1) your secondTable = dt1 after that again IEnumerable<DataRow> dt2 = secondTable.AsEnumerable().Take(100); I hope it's helpfull

              modified on Friday, July 25, 2008 8:31 AM

              P Offline
              P Offline
              panyl
              wrote on last edited by
              #6

              Thank you very much!i will try. Thank you!

              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