Solved

A Simple Question on Relationships

Posted on 2006-06-28
2
450 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

737 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