Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ManyToMany Headache

Posted on 2006-11-14
8
Medium Priority
?
163 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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

916 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