Results 1 to 4 of 4

Thread: Finding a Row Within a Data Table

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Finding a Row Within a Data Table

    I'm trying to find a value a value within a data table based on a record I'm reading from another table.

    For example, I have a number called "PCS Visit" in my first table. While looping through the records in that table, I throw the data into a datagridview. One of the values I need is in another table though.

    To get the other value, I'm trying to say "go find the row in table 2 where the PCS visit number = the current record's PCS Visit Number". When you find it, bring back the "AdmitBed" associated with the PCS Visit Number in table 2.

    My FoundRow = dsNRCPicker row seems to work, I just don't know how to get the value for AdmitBed from the row it found.

    Code:
                    Dim FoundRow() As Data.DataRow
                    FoundRow = dsNRCPicker.Tables("dtAdmitBed").Select("PCS_Visit = " & DataReader.Item("PCS_Visit"))
    
                    anyRow("AdmitBed") = FoundRow :(

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Finding a Row Within a Data Table

    Try this
    Code:
            Dim FoundRow() As Data.DataRow
            FoundRow = dsNRCPicker.Tables("dtAdmitBed").Select("PCS_Visit = '" & DataReader.Item("PCS_Visit").ToString & "'")
    
            If FoundRow.Length = 1 Then
                anyRow("AdmitBed") = FoundRow(0)("AdmitBed")
            End If
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

  3. #3

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Finding a Row Within a Data Table

    It didn't care for the .ToString & "'") business that you added but I removed that, and BINGO.

    Thanks - that is a very big help.

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: Finding a Row Within a Data Table

    Option Strict is your friend
    That is the very essence of human beings and our very unique capability to perform complex reasoning and actually use our perception to further our understanding of things. We like to solve problems. -Kleinma

    Does your code in post #46 look like my code in #45? No, it doesn't. Therefore, wrong is how it looks. - jmcilhinney

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width