Solved

A Simple Question on Relationships

Posted on 2006-06-28
2
448 Views
Last Modified: 2012-06-22
I have two tables tblA and tblB.Both tables contain field "Name" but when i tried to add foreign
key relationships between them as

 Dim fk As New ForeignKeyConstraint(ds.Tables("tblA").Columns("Name"), ds.Tables("tblB").Columns("Name"))
        fk.AcceptRejectRule = AcceptRejectRule.Cascade
        fk.DeleteRule = Rule.Cascade
        fk.UpdateRule = Rule.Cascade
        ds.Tables("tblA").Constraints.Add(fk)
        ds.EnforceConstraints = True
It produces an error message as
"This constraint cannot be added since ForeignKey doesn't belong to table tblA".

Any hints?
0
Comment
Question by:biplavo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 80 total points
ID: 17000577
This line

        ds.Tables("tblA").Constraints.Add(fk)

should be

        ds.Tables("tblB").Constraints.Add(fk)

Have a look at this

http://msdn2.microsoft.com/en-us/library/ta3c32z8.aspx

In the terms used in the example in that, tblA.Name is the parent and tblB.Name is the child, and the constraint should be added to the child table, not the parent table.

Roger
0
 

Author Comment

by:biplavo
ID: 17065189
Yup...
Thanks Sancler.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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