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. DataRow with specified value & index ?

DataRow with specified value & index ?

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdatabase
3 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.
  • N Offline
    N Offline
    numbrel
    wrote on last edited by
    #1

    In VB.NET 2 part question: I want a DataRow that contains a column with a specified value. Part 1: would the following work to identify the row that contains the value and assign it to the DataRow?: drPart = DsParts1.Tables("EventID").Rows.Find(iEventId) ‘where EventID is the column and iEventId is the value. Part 2: Once I have identified the row with the value and assigned it to drPart, how do I assign the index of that row in the table to iIndex variable? Thanks.

    R 1 Reply Last reply
    0
    • N numbrel

      In VB.NET 2 part question: I want a DataRow that contains a column with a specified value. Part 1: would the following work to identify the row that contains the value and assign it to the DataRow?: drPart = DsParts1.Tables("EventID").Rows.Find(iEventId) ‘where EventID is the column and iEventId is the value. Part 2: Once I have identified the row with the value and assigned it to drPart, how do I assign the index of that row in the table to iIndex variable? Thanks.

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      1. Will work only if the value you are searching for is in your PrimaryKey column. If not use the DataTable.Select function. You can even use complex queries there. 2. I think there is no elegant way to get the index. If your really need it you will have to determine it yourself: public int IndexOf(DataRow row, DataTable table) { for (int i = 0; i < table.Rows.Count; i++) if (table.Rows[i] == row) return i; return -1; } Note that this is not very effective and should not be used with large DataTables.

      N 1 Reply Last reply
      0
      • R Robert Rohde

        1. Will work only if the value you are searching for is in your PrimaryKey column. If not use the DataTable.Select function. You can even use complex queries there. 2. I think there is no elegant way to get the index. If your really need it you will have to determine it yourself: public int IndexOf(DataRow row, DataTable table) { for (int i = 0; i < table.Rows.Count; i++) if (table.Rows[i] == row) return i; return -1; } Note that this is not very effective and should not be used with large DataTables.

        N Offline
        N Offline
        numbrel
        wrote on last edited by
        #3

        Thank you, Robert. I have been working on it and between two VB.NET books I was able to figure out how to use select method to form a subset. You are right about using select, it was much simpler than what I had originally thought to do. I was going to use the index (if it existed) and move through the data table to find the rows I wanted.

        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