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. Web Development
  3. ASP.NET
  4. How to get a datarow from a datable in C#?

How to get a datarow from a datable in C#?

Scheduled Pinned Locked Moved ASP.NET
csharptutorialquestion
4 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
    salon
    wrote on last edited by
    #1

    :) I have a datatable which is having n no. of rows and each row has a unique field say ID. Now I want to get a particular row for a specified ID. eg. there are 5 rows in a datatable and the id's are 1,2,3,4 and 5 and if I want to select a row having ID = 4 What will be the code snippet for that? Does anybody have any idea? Thanks in advance,

    H J 2 Replies Last reply
    0
    • S salon

      :) I have a datatable which is having n no. of rows and each row has a unique field say ID. Now I want to get a particular row for a specified ID. eg. there are 5 rows in a datatable and the id's are 1,2,3,4 and 5 and if I want to select a row having ID = 4 What will be the code snippet for that? Does anybody have any idea? Thanks in advance,

      H Offline
      H Offline
      Herman T Instance
      wrote on last edited by
      #2

      IF your datatable hasn't got too many rows you could o the trick with: foreach (DataRow row in dataTable.Rows) { if (row["ID"].Equals(4)) { } }

      S 1 Reply Last reply
      0
      • H Herman T Instance

        IF your datatable hasn't got too many rows you could o the trick with: foreach (DataRow row in dataTable.Rows) { if (row["ID"].Equals(4)) { } }

        S Offline
        S Offline
        Syed Ali Raza
        wrote on last edited by
        #3

        You can do it like this dataTable.rows[4]["ColumName"].tostring()

        1 Reply Last reply
        0
        • S salon

          :) I have a datatable which is having n no. of rows and each row has a unique field say ID. Now I want to get a particular row for a specified ID. eg. there are 5 rows in a datatable and the id's are 1,2,3,4 and 5 and if I want to select a row having ID = 4 What will be the code snippet for that? Does anybody have any idea? Thanks in advance,

          J Offline
          J Offline
          J4amieC
          wrote on last edited by
          #4

          Stick with the answer you got in the C# forum. It is the better way to achieve this.

          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