Solved

ManyToMany Headache

Posted on 2006-11-14
8
158 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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to use odbc in vb to connect to ms sql 14 52
Vb. Net application freezes 9 45
I need help converting a bitmap to an image in VB.Net 1 32
.NET 2008 VB and C# 6 27
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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