Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

ict-torquilclark
ict-torquilclark used Ask the Experts™
on
I have a table adapter with the attatched SQL query in the select statement...

When I fill the tableadapter i get the error in the title


Can anybody help?

SELECT P.PolicyRef,P.PolicyNumber, UP.UnitName, S.SchemeName,C.ClientRef
FROM UnitPriceAnalysis UPA
INNER JOIN ((((FundHoldings FH 
INNER JOIN Policies P
ON FH.FKeyRef = P.PolicyRef) 
INNER JOIN UnitPrices UP 
ON FH.UnitPriceRef = UP.UnitPriceRef) 
INNER JOIN Clients C 
ON P.ClientRef=C.ClientRef) 
INNER JOIN Schemes S 
ON P.SchemeRef=S.SchemeRef) 
ON UPA.UnitPriceRef=UP.UnitPriceRef
WHERE  P.ShowOnPortfolio=1 AND FH.FKeyType=2 AND C.ClientRef = @ClientRef

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
If i open the datatable, input the parameter and do a preview data it runs fine...
Distinguished Expert 2017
Commented:
The issue is not with the query, but with the data you are trying to insert which does not meet the constraints that are defined for the table.

Check the table into which the data is being inserted what the constraints are, what fields can not be null, etc.
Then look at the ouput of the query.

 

Author

Commented:
Im not trying to insert anything - it is a SELECT Query...
Distinguished Expert 2017

Commented:
Could you post the create table scripts for each of the tables used in the query?
Where is the @ClientRef coming from ?

Author

Commented:
You were right - clientref was the primary key...

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial