Solved

ManyToMany Headache

Posted on 2006-11-14
8
159 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
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.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
send messages to whatsapp programatically 2 67
VB.net Open Folder in Windows Explorer 3 59
Help with exporting to excel 4 37
VB.NET Textbox input validation 4 41
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

820 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