Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to tables. One for salesH(sales head storing like billno, billdate, customer name, gross total,discounts,net total) and other for sales(billno, item name,item qty,
item price,item total).salesH.billno is having index key and foregin key of billno of sales.I am creating a reportwith C# report viewer.but when i am executing one error is coming."
"Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints"
.I am creating this with system generated sql query with query builder. I executed that query in SSMS. It is showing result. but Here only prob. Here my sql query
SELECT        sales.itemname, salesH.taxable, salesH.custname, sales.qty, sales.price, sales.tax, sales.Itemtot, sales.pertonum, salesH.nettot, salesH.discount, salesH.billtax, salesH.grosstot, salesH.billno
FROM            sales INNER JOIN
                         salesH ON sales.billno = salesH.billno
"


What I have tried:

I checked data and query in SSMS also.it is coming there.Problem with enable constraints. so what is this. why is coming. what I have to do now.
Posted
Updated 19-Apr-17 20:59pm
v4
Comments
Tomas Takac 20-Apr-17 3:03am    
I suspect this is the same problem as in your last question. Did you turn off the constraints, imported data and then tried to turn on the constrains again?

The problem is that you are putting some quality restrictions on your data such as foreign keys or non-null constrains but your data is just doesn't match. I would suggest you import all data into a staging table without any constraints, then validate it and only move the valid records to the live table. You can also produce a nice quality report for your users in the process.
vijay_bale 20-Apr-17 8:45am    
I copied My query result into a database file and from there I am generating reports.

1 solution

 
Share this answer
 
Comments
Tomas Takac 20-Apr-17 9:01am    
I don't think removing foreign keys is a valid solution here. OP needs to clean up the data instead.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900