473,545 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataSet 1 to many Relation - How to?

I have two tables in the DataSet, the first present rooms and the other
furniture kinds.

Furniture kind, like chare, can be in more then one room. And specific room
can contain more then one furniture kind (chare + table + ...). Therefore,
the room table should have Relation that point to several furniture kind, and
the furniture table should have Relation to several rooms.

Is there a way to define this kind of relation from one to many?
If so - How?

Any advice will be highly appreciated.
---------
Thanks
Sharon G.
Nov 17 '05 #1
14 2887
hi,

Really it's a many to many relationship and you need an extra table to hold
this. this table will have a FK to both rooms & furniture kinds
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Sharon" <Sh****@discuss ions.microsoft. com> wrote in message
news:6E******** *************** ***********@mic rosoft.com...
I have two tables in the DataSet, the first present rooms and the other
furniture kinds.

Furniture kind, like chare, can be in more then one room. And specific
room
can contain more then one furniture kind (chare + table + ...). Therefore,
the room table should have Relation that point to several furniture kind,
and
the furniture table should have Relation to several rooms.

Is there a way to define this kind of relation from one to many?
If so - How?

Any advice will be highly appreciated.
---------
Thanks
Sharon G.

Nov 17 '05 #2
Can you please axplain how do I do that?

Note: I'm designing a model using XSD file that the VS .NET generate a
DataSet object from it.
-------
Thanks
Sharon G.
Nov 17 '05 #3
Hi,

You create a table with two column, each column is a FK to the PK of the
other tables (furniture, room ), Note that they both "may" not be declare
as PK ( a room with more than one particular kind fo furniture) so either
you declare another column or just work the table without PK.

Now, I have never used the designer from VS.NET so I don't know for sure how
to do it, I use XDE there you select the relationship ( many to many ) and
just click two tables, a new table & the relationships will be generated.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Sharon" <Sh****@discuss ions.microsoft. com> wrote in message
news:DD******** *************** ***********@mic rosoft.com...
Can you please axplain how do I do that?

Note: I'm designing a model using XSD file that the VS .NET generate a
DataSet object from it.
-------
Thanks
Sharon G.

Nov 17 '05 #4
After looking further to the solution you have suggested, I'm puzzled with
two unclear questions:
(1) If I have 3 rooms and 12 furniture all together, 4 furniture in each
room. How many ROOM_FURNITURE tables will be created in this case that will
hold the bi-directional relations between the rooms and the furniture
(relations that point from furniture to room and from room to furniture) ?
How the ROOM_FURNITURE will look like?

(2) Lets say I'm trying to find the furniture that room 3 contains.
So, I go from room 3 row through its key to the ROOM_FURNITURE row in the
ROOM_FURNITURE table, but now I need to find to which furniture to go to
because there are many furniture in that room or even many furniture for all
the other rooms.
-------
Thanks
Sharon G.
Nov 17 '05 #5
Sharon wrote:
After looking further to the solution you have suggested, I'm puzzled with
two unclear questions:
(1) If I have 3 rooms and 12 furniture all together, 4 furniture in each
room. How many ROOM_FURNITURE tables will be created in this case that will hold the bi-directional relations between the rooms and the furniture
(relations that point from furniture to room and from room to furniture) ?
How the ROOM_FURNITURE will look like?
The link table will look somewhat like:

room_id
furniture_kind_ id
kind_count (if you have more than one chair in a room)

There will be a row for each kind of furniture in each room:

room_id furniture_kind_ id kind_count
=============== =============== =
3 1 1
3 2 2
3 3 1
4 1 2
4 2 4
....

with a furniture_kind_ table like

id name
========
1 bed
2 chair
3 table
(2) Lets say I'm trying to find the furniture that room 3 contains.
So, I go from room 3 row through its key to the ROOM_FURNITURE row in the
ROOM_FURNITURE table, but now I need to find to which furniture to go to
because there are many furniture in that room or even many furniture for all the other rooms.


You'd select all rows from the link table with room_id = 3. In the above
example, that would be three rows:

room_id furniture_kind_ id kind_count
=============== =============== =
3 1 1
3 2 2
3 3 1

From each furniture_kind, (1, 2 or 3), you can then select the appropriate
entry of the furniture_kind_ table.

Nov 17 '05 #6
Hi,

Responses to your questions are inline.

Now I have a question, does the furniture table hold furniture types or
furnitures instances, please note they are different, a Furniture type are
generics entities ( sofa, chair, loveseat, etc ) with certain properties. A
furniture instance is the black leather sofa placed in the livingroom.

I hope you see the difference. I can show you a UML model with both
escenarios if you need further clarification.

"Sharon" <Sh****@discuss ions.microsoft. com> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
After looking further to the solution you have suggested, I'm puzzled with
two unclear questions:
(1) If I have 3 rooms and 12 furniture all together, 4 furniture in each
room. How many ROOM_FURNITURE tables will be created in this case that
will
hold the bi-directional relations between the rooms and the furniture
(relations that point from furniture to room and from room to furniture) ?
How the ROOM_FURNITURE will look like?
Only one table !!!
with 3*4 rows
Will look like this ( I scripted a piece of one DB and changed the names of
tables/columns , hope it will be clear enough )

ALTER TABLE [dbo].[Room_Furniture] ADD
CONSTRAINT [Constraint19] PRIMARY KEY NONCLUSTERED
(
[roomID],
[furnitureTypeID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Room_Furniture] ADD
CONSTRAINT [Constraint18] FOREIGN KEY
(
[roomID]
) REFERENCES [dbo].[RoomTable] (
[pID]
),
CONSTRAINT [Constraint20] FOREIGN KEY
(
[furnitureTypeID]
) REFERENCES [dbo].[FurnitureType] (
[uID]
)
GO
(2) Lets say I'm trying to find the furniture that room 3 contains.
So, I go from room 3 row through its key to the ROOM_FURNITURE row in the
ROOM_FURNITURE table, but now I need to find to which furniture to go to
because there are many furniture in that room or even many furniture for
all
the other rooms.


You can use any of these queries:

SELECT * FROM FurnitureType WHERE FurnitureTypeID in ( SELECT
FurnitureTypeID FROM Room_Furniture WHERE roomID = 3 )

or this other:

SELECT Furniture.* FROM FurnitureType, Room_Furniture WHERE
FurnitureType.F urnitureTypeID = Room_Furniture. FurnitureTypeID AND
Room_Furniture. RoomID = 3


cheeers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Nov 17 '05 #7
Thanks for the answers.

Ignacio - The furniture table hold furniture types.
Michael & Ignacio - I can see now how its work, but as I see it it's very
un-efficient, because the select need to search for all rows with value of
room 3.

Can I make it more efficient? I have heard that index will help. Can you
shade some light on this issue?

-------------
Thanks again
Sharon G.
Nov 17 '05 #8
Sharon wrote:
Michael & Ignacio - I can see now how its work, but as I see it it's very
un-efficient, because the select need to search for all rows with value of
room 3.
Why do you consider this inefficent ? You'd just select everything from that
table "where room_id = 3"; this would return the three rows.

Can I make it more efficient? I have heard that index will help. Can you
shade some light on this issue?
If the selects are too slow, setting an index on each id-column (room_id and
funriture_kind_ id) will help most likely.


-------------
Thanks again
Sharon G.

Nov 17 '05 #9
That's good I thought so too.

can you explain what the indexing mean and how would I add it?
--------------
Thanks a lot
Sharon G.
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6691
by: Ian Griffiths | last post by:
I have been given a schema, instances of which I'm required to be able to consume and generate. I'd like to be able to manipulate these instances as DataSets internally in my application. The schema defines the following simpleType: <xs:simpleType name="cs"> <xs:restriction base="xs:token"> <xs:pattern value="*"/> </xs:restriction>...
1
2326
by: Fernando | last post by:
I will explain the problem that i have with as much detail as i can. I have an application developed using C# & SQL 2000. I am using a relational database scheme. The problem is present in this part of the application: I have two tables, "Providers" & "Providers_Telephones", connected by a relation: 1 Provider -> many Telephones. I have...
4
2227
by: Mat | last post by:
I have typed dataset and i don't know how to filter rows of table A according to children rows in table B Example TABLE USER has columns ID,Name Table USERNICK has columns nickname, ID Relationship is : each user can have many nicksname. (1,N)
14
2109
by: Lars Netzel | last post by:
A little background: I use three Datagrids that are in a child parent relation. I Use Negative Autoincrement on the the DataTables and that's workning nice. My problem is when I Update these grid and write to the database and I set the new Primary Keys and related Fields to the new asigned atuonumbers in the Access.
5
2620
by: Corno | last post by:
Hi all, If I want to provide a typed dataset from a webservice and if that dataset has relations that are nested (isNested=True), then the relations(keyrefs) are not available in the XSD that is offered. If I set IsNested to false or default, then it is included in the XSD. Is this a bug or by design? Corno
4
1429
by: Robert Bravery | last post by:
Hi All, I'm New to VS.net. Trying to figure out this new dataset thingy. Ok so I add a dataadapter with all the correct properties for a table. Then generate the dataset. Now open the dataset and drag another table from the server explorer, set up some relations there. Set up two grids, one a s a parent one as a chgild. Fill the dataset, run...
4
2087
by: Robert Bravery | last post by:
Hi all, I have now correctly set up my dataset and two grids, so that the parent navigates the child. THe thing is that the child table is actually a lookup type table. It lists billing types for the parent table, so that I just store a key in the parent table, and the show the billing type description from the child I need to set this up in...
2
2858
by: Joe | last post by:
Hi I have a dataset with 3 tables and 2 relations Is there a way to when I am at 1 row to tell if there is a relation on that row ??? I have the code hardcoded but try to make it work if the # of tables and #relations increase or decrease So I can just pass any dataset and walk thru the rows?? Thanks
1
1819
by: Computer | last post by:
I brought an XSD into the XMLDesigner. The XSD had two related tables and it looked like this in .Net's XMLDesigner: Table 1 --------- BankItem (Bank Item)
0
7420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7680
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6003
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3476
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.