How can I Find values in a DataTable?

Hello folks,

in VB .NET: I have made a table with 2 columns - 1. is the primary key, 2. contains whatever info. When i use the myTable.rows.find(primarykey)-method VB finds the row with the specified primary key value, and then I can extract the value in the 2. column. But, how can I do the opposite, i.e. make VB find a specified value in the second column such that I can extract the primary key(s)

I guess there is an easy way to do this, but I've not been able to find it :-(

Hope anyone can help...



Answer this question

How can I Find values in a DataTable?

  • Oliver 123

    Oh yes, this solves the problem... many thanks :-))
  • CalinMac

    Your best bet here is to create a select statement to find the rows. Say your columns are named Col1 and Col2. Here is a method that will generate a select statement to return the values you're looking for.

    Function FindByValue(ByVal str As String) As DataRow()
     Dim sel As String = String.Format("Col2='{0}'", str)
     return myTable.Select(sel)
    End Function
    


  • How can I Find values in a DataTable?