Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dataview questions

Status
Not open for further replies.

cjelec

Programmer
Jan 5, 2007
491
GB
Hi,

I'm tring to filter a dataview based on the value of the child datatable

For example:

Clients (Parent)
Id (PK)
Name
Address
...

Orders (Child)
Id (PK)
Client_Id (FK)
ItemCode
ItemName
...

The relation for the two tables has been setup and I have a ListBox on a form to show the client names... I use a normal DataView and it works fine, but I want to filter the Clients by the ones who have brought a TV for example...

I have read that you use the DataViewManager, but after playing around with it and finding out that it works the other way (Filter Parent to get Children), I'm stumped...

How can I do this?

Thanks in advance
 
Cjelec,

Have you managed to find a solution to this? I have a similar issue relating to employees and their assignments but I want to find people in a particular job.

The only way I've found to do it at the moment is to loop through the filtered child table recording the ID's in a string. Once the child table has been stepped through I was then going to apply the filter using the string to the parent. Code below needs tidying but it should give you an idea.

Code:
datatable(child).defaultview.rowfilter = "ItemCode = 'TV'"

strFilter = ""

for each row in datatable(child).defaultview
  strFilter = strFilter &  row.item([Client_Id]) & ","
next

datatable(parent).defaultview.rowfilter = "ID in (" & strfilter & ")

Obviously this isn't too bad when you've only got a small amount of records but could be very slow if there's a lot.

Any other suggestions would be welcome.

Cheers
Chris
 
Wow, I forgot about this thread,

No sorry, I didn't find a way to do this other than something like the one you suggested. My problem was, I had 30,000+ records to deal with so manually going through the child ones wasn't an option.

There is one option, put the parent/child data in the same table (just thought of that now), it does go against the whole idea of databases/tables.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top