.Find Method w/multiple keys

  • Thread starter Thread starter DDW
  • Start date Start date
D

DDW

I've got a dataset (ratesds2) containing multiple relational tables
(3) for which I'd like to find a single child record.

Table(1) contains a single record for each product and table(2)
contains details for the product. The product details table is
"nested" based on the productID. Table one has a single key field
(productID) and table two has two key fields with productID from table
1 being one of the two and the other a unique product attribute key.
Dataset is correctly defined with the two primary key fields in table
2.

All I want to do is retrieve a specific row from table 2 given the two
key fields as follows and put the value of a single field into string
variable;

Sample Code
-----------------------------------------------
Dim filterstring As String = "productid = '123'"

Dim productdetailsview As New DataView
productdetailsview = ratesds2.Tables(2).DefaultView
productdetailsview.RowFilter = filterstring

Dim foundRowsc() As DataRowView = productdetailsview.Find(New
Object() "123", "C"})

dim attribiute_c as string = foundRowsc(0)("Details")

This doesn't work. Any ideas?
 
Dim findTheseVals(1) As Object

For Each mRow In dt1.Rows
findTheseVals(0) = mRow("KeyField1")
findTheseVals(1) = mRow("KeyField2")
foundRow = dt2.Rows.Find(findTheseVals)

If foundRow Is Nothing Then
 
DDW,
Find will work only against the primary key of the table. You can use
select on the table to get an Array of DataRows matching the criteria. Just
use (in my approximate VB translation)
Dim dataRows as DataRow()
dataRows = ratesds2.Tables(2).Select("(productid = '123') AND (the rest of
the criteria)")
If the search is specific enough you will just get one item in the array.

I'd probably use String.Format to build the criteria easily from parameters
in code.

Ron Allen
 
Back
Top