Urgent!!! DataRelation Fails

  • Thread starter Thread starter Ernesto Tejeda
  • Start date Start date
E

Ernesto Tejeda

Hello everyone



(VS 2k3 + SQLSRV 2K)

I've been having troubles trying to make a data relation work. I have seven
tables related to an eighth one. I created the relation visually using the
XML Designer but for some strange reason the relations fail and when I try
to preview the data in the Data Adapter Preview for one of the child tables
it gives the exception:



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



The same error message happens when I try to fill the data adapter at
runtime.



I just don't get it. I've recreated the relations many times. recreated all
the data adapters. recreated the data source. recreated the component that
holds the data adapters and the data source. recreated every thing many
times. tested with just one data adapter. with two. and sometimes it works
just fine. others don't.



Any hints?
 
Well, make sure your actual data tables have all the same constraints as
your real tables. Then make sure you aren't doing any outer joins. If you do
a right outer join and select non-null columns from the right table, you
might get some nulls, and those would violate the data table constraints.

Chris C.
 
Kind of expand on a little bit on Chris's point. A
DataRelation is similar to a primary key/foreign key
relationship in the database. When you add the
DataRelation to the DataRelationCollection, it first
checks the data in both tables to make sure there is no
violation. An exception is generated if there is a
violation. So most likely the problem is in your data, not
the way the DataRelation is added through VS.
 
Back
Top