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 index/indices of a row in a DataTable

How to get index/indices of a row in a DataTable

Scheduled Pinned Locked Moved C#
tutorialdatabasequestioncareer
2 Posts 2 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.
  • A Offline
    A Offline
    AesopTurtle
    wrote on last edited by
    #1

    Hi, is there any way to get index/indices of a row where the content of a column is as specified. For example, the following table named "employee" contains 3 columns with 4 datarows.

    [employee]
    (emp_id)•(emp_name)•(salary)
    00001 Johan 30000
    00002 Joseph 35000
    00003 Jack 28000
    00004 Jane 32000

    I'd like to find the index of a row where emp_name is "Joseph". Is there any way to get it? I've tried to use IndexOf() method to get it but it asks for a datarow as its parameter which i don't even know where it is in the table -_-"

    DataTable dt = ds.Tables["employee"];
    int i = dt.Rows.IndexOf(); <-- don't know what to put here.

    Thank you so much. KiT

    E 1 Reply Last reply
    0
    • A AesopTurtle

      Hi, is there any way to get index/indices of a row where the content of a column is as specified. For example, the following table named "employee" contains 3 columns with 4 datarows.

      [employee]
      (emp_id)•(emp_name)•(salary)
      00001 Johan 30000
      00002 Joseph 35000
      00003 Jack 28000
      00004 Jane 32000

      I'd like to find the index of a row where emp_name is "Joseph". Is there any way to get it? I've tried to use IndexOf() method to get it but it asks for a datarow as its parameter which i don't even know where it is in the table -_-"

      DataTable dt = ds.Tables["employee"];
      int i = dt.Rows.IndexOf(); <-- don't know what to put here.

      Thank you so much. KiT

      E Offline
      E Offline
      esjq
      wrote on last edited by
      #2

      DataTable dt=ds.Tables["employee"]; DataRow[] arr=dt.Select("emp_name='Joseph'"); textBox1.Text=arr[0].ItemArray["emp_id"].ToString(); Worth noting, if you have several persons named Joseph you simply can not take the first one. To obtain uniqueness it is better to work with the id-column. HTH

      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