Solved

A Simple Question on Relationships

Posted on 2006-06-28
2
444 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
Comment Utility
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
Comment Utility
Yup...
Thanks Sancler.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Sort Datagrdview programmatically 19 34
Custom auto number 6 51
MS access and calling saved Queries 4 25
Change data in datatable 8 15
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

9 Experts available now in Live!

Get 1:1 Help Now