Solved

ManyToMany Headache

Posted on 2006-11-14
8
160 Views
Last Modified: 2010-04-23
I have a many to many relationship between 2 tables using a junction table

Table1

PortID
Name
Description

Junctiontable
PortID
RekID

Table2
RekID
Name
Description

I load these tables in a typed dataset

I have a DataEntry form where I want to do the following
when somebody chooses a record from table1 I want a combobox that gives me only the records from table2 that are related to the choosen PortID.

HOW ????

I know I could create a new table in my typed dataset just for this purpose but is there a way to avoid that ???
0
Comment
Question by:Strategus
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 17940122
in general, try setting it like this:
assuming you show table1 in a datagridview, set its DataSource to the typed dataset, and the DataMember to table1. on your combobox, set the DataSource to the table1bindingsource, and its datamember to the FK binding source.

or you can do it visually. go to the data source pane and navigate to table 1. if the relationships are there, there should be a + sign next to its name. if you click on that + you will get table2 inside table1 (notice that table2 is also present outside of table1). just drag and drop table1 to the form, and the table2 which is inside table1. i believe the designer will automatically create everything you need.

0
 

Author Comment

by:Strategus
ID: 17941173
Thank you for your comment but unfortunately it is not that simple, I apologize for not explaining it more clearly. Here is a more elaborate explanation:

I actually want you use the information I gave above in a fourth table which looks like this

OrdId
Portid
RekID
and a lot of other field

I fill these fields in a dataentry form where you choose the portId in a combobox,  in the selectedvaluechanged event of the combobox I need to fill the next combobox with the rekIDs and Description that are related to  that portID

I hope this explains it a bit better

0
 
LVL 13

Expert Comment

by:newyuppie
ID: 17944541
an approach could be to handle the selectedvaluechanged like you want, using a property of the datarows which is GetChildRows, looping it and adding to the other combobox

for each dr as DataRow in table4.getchildrows("name of datarelation")
  combobox2.items.add(dr("name of foreign column")
next dr

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:Strategus
ID: 17945404
Yes if it was a OneToMany relation, but unfortunately it is a ManyToMany, so I don't need the childrows I need the parentrows of the childrows
0
 
LVL 34

Expert Comment

by:Sancler
ID: 17945904
Rather than trying to use datarelations, you may find it easier to (in effect) "roll you own".

Bind the Table2 combo to a DataView.  When a selection is made in Table 1 use the PortID from that to read the appropriate RekID from the Junction table and then use that as the rowfilter on the Table2 DataView.

Roger
0
 

Author Comment

by:Strategus
ID: 17945947
Hi Sancler, good suggestion, but what would be more efficient (performance wise), your suggestion or just loading a combined table (junction + table2) into a separate table (outside the typed dataset)  and use that in my combobox
0
 
LVL 34

Accepted Solution

by:
Sancler earned 500 total points
ID: 17946198
Strategus

The combined table, I think.  Not tested but my thinking is that the creation of the combined table has to be done once whereas the look-up on my suggestion would have to be done every time.

Roger
0
 

Author Comment

by:Strategus
ID: 17946276
Thats what I thought aswell :=), I'll go with that option than.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question