Q: Searching the result of relationship

  • Thread starter Thread starter Geoff Jones
  • Start date Start date
G

Geoff Jones

Hi

How can I search, using SQL commands, an arrow of rows generated from
GetChildRows. For example, suppose the result is given by:

Dim drMyRows() As DataRow = myTable(0).Rows.GetChildRows("MyChoices")

I would like to search for all the rows in drMyRows which satisfy an SQL
condition. I thought there may be a "Select" or "RowFilter" method I could
use but I can't find an example of one.

The only other thing I can think of is to iterate through each row and check
each one against the condition. Okay, it'll work, but I'd hoped there was an
inbuilt way to do it; if only in the hope it would be faster and more
efficient?

Can anybody help?

Thanks in advance

Geoff
 
Hi Geoff,

I showed you more times that when there is a childrelation, there should be
a filter item that makes the relation. You do not want to use that, why?

Am I missing something?

Cor
 
Geoff,
I'm not sure if this will work, but, it may help to get you in the right
direction. How are you getting an array of rows with out specifing which row
to get child rows from? Your code: Rows.GetChildRows("MyChoices"), Example
Code: Rows(0).GetChildRows("MyChoices").

Dim Rows() As DataRow = ds.Tables(0).Rows(0).GetChildRows("MyChoices")
Dim dt As New DataTable
For Each row As DataRow In Rows
dt.ImportRow(row)
Next
Rows = dt.Select("MyColumn=MyValue")

'OR

'Dim dv As New DataView(dt)
'Filter here
 
Hi Cor

No, your solution is very elegant and does indeed work. However, it does
surprise me that there are no other alternatives i.e. I would have expected
some kind of "Select" or "RowFilter" for an array of Rows. Obviously I'm
mistaken.

Geoff
 
Geoff,
How's that go? The third time is the charm.

I've answered this for you on both 7/6 & 7/13.

Instead of DataRow.GetChildRows use a DataView and use
DataRowView.CreateChildView.

Then you can set the RowFilter property of the DataView returned.

Dim view As New DataView(myTable)

For Each parent As DataRowView In view
Dim prices As DataView = parent.CreateChildView("PricesCompany")
prices.RowFilter = "Prices = '2'"
For Each price As DataRowView In prices
Debug.WriteLine(price!Prices, "Prices")
Debug.WriteLine(price!Company, "Company")
Next
Next

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Q: An array of rows 5
Q: GetChildRows 2
Q: Searching 1
Q: Index for a row 8
Q: DataRow in a ArrayList 2
Searching a table 33
Help with searching DataRow array... 2
Q: SQL 9

Back
Top