Solved

A Simple Question on Relationships

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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