Solved

A Simple Question on Relationships

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
A short film showing how OnPage and Connectwise integration works.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

932 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now