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. C#:How to navigate through records in a datatable/dataset

C#:How to navigate through records in a datatable/dataset

Scheduled Pinned Locked Moved C#
csharphelptutorial
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.
  • K Offline
    K Offline
    kssknov
    wrote on last edited by
    #1

    hi all i have a form with First,Next,Prev,Buttons. i had populated a datatable with datas .Now i need to navigate through the records , can any body help me how to achieve this. conn = new SqlConnection(connstr); conn.Open(); SqlCommand cmd = new SqlCommand(sqlAllCustomers, conn); SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); thanks

    senthil

    Mircea PuiuM M P 3 Replies Last reply
    0
    • K kssknov

      hi all i have a form with First,Next,Prev,Buttons. i had populated a datatable with datas .Now i need to navigate through the records , can any body help me how to achieve this. conn = new SqlConnection(connstr); conn.Open(); SqlCommand cmd = new SqlCommand(sqlAllCustomers, conn); SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); thanks

      senthil

      Mircea PuiuM Offline
      Mircea PuiuM Offline
      Mircea Puiu
      wrote on last edited by
      #2

      dtCust1.Rows[index]["columnName"]

      SkyWalker

      1 Reply Last reply
      0
      • K kssknov

        hi all i have a form with First,Next,Prev,Buttons. i had populated a datatable with datas .Now i need to navigate through the records , can any body help me how to achieve this. conn = new SqlConnection(connstr); conn.Open(); SqlCommand cmd = new SqlCommand(sqlAllCustomers, conn); SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); thanks

        senthil

        M Offline
        M Offline
        M Aamir Malik
        wrote on last edited by
        #3

        This might not be the best of the methods but I use to do like that dtCust1.Rows[i][columnName] --> this will give you the value in the datatable for the row "i" and column "columnName". Now for the next record increment the value of "i" by one, for previous record decrement the value of "i" by one, for First record set the value of "i" to 0 and for Last record set the value of "i" to dtCust1.Rows.Count. Hope this helps. Regards

        K 1 Reply Last reply
        0
        • K kssknov

          hi all i have a form with First,Next,Prev,Buttons. i had populated a datatable with datas .Now i need to navigate through the records , can any body help me how to achieve this. conn = new SqlConnection(connstr); conn.Open(); SqlCommand cmd = new SqlCommand(sqlAllCustomers, conn); SqlDataAdapter adpt = new SqlDataAdapter(cmd); DataTable dtCust1 = new DataTable("CustomerDatTab"); adpt.Fill(dtCust1); thanks

          senthil

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          You could use either:

          for (int i = 0; i < dtCust1.Rows.Count; i++)
          {
            DataRow row = dtCust.Rows[i];
            Console.WriteLine(row[0]); // This would print the first column in the each row.
          }
          

          or

          foreach (DataRow row in dtCust1.Rows)
          {
            Console.WriteLine(row[0]); // This would print the first column in the each row.
          }
          

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          1 Reply Last reply
          0
          • M M Aamir Malik

            This might not be the best of the methods but I use to do like that dtCust1.Rows[i][columnName] --> this will give you the value in the datatable for the row "i" and column "columnName". Now for the next record increment the value of "i" by one, for previous record decrement the value of "i" by one, for First record set the value of "i" to 0 and for Last record set the value of "i" to dtCust1.Rows.Count. Hope this helps. Regards

            K Offline
            K Offline
            kssknov
            wrote on last edited by
            #5

            hi aamir i too did so , its working . Thank u for responding me. kssk

            senthil

            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