Solved

ManyToMany Headache

Posted on 2006-11-14
8
156 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
  • 4
  • 2
  • 2
8 Comments
 
LVL 13

Expert Comment

by:newyuppie
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:Strategus
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 34

Expert Comment

by:Sancler
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thats what I thought aswell :=), I'll go with that option than.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now