Merging Tables and Data Constraints RRS feed

  • Question

  • I am trying to merge two data tables with similar schema. I have had success with doing this, but all too often I get a very frustrating "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints." No useful information about what constraint was violated on what row. 

    For example. If I have to tables as follows:


    ArticleID (PK)
    CollectionID {PK}

    ArticleID (PK)
    CollectionID (PK)
    Family (PK)

    I then try to merge them like this:

    //Merge the table for this text with the master table
                        dataSet1.EnforceConstraints = false;
                        Table1.Merge(Table2, false, MissingSchemaAction.Add);
                        dataSet1.EnforceConstraints = true;

    It works! ...until I try to re-enable constraints and the error is shown. 

    I can see no constraints or erroneous data in either table that would cause this. 

    Does anyone know why this error would be thrown?

    Wednesday, December 19, 2012 3:39 PM


  • This problem is usually caused by either null values being returned for columns not set to AllowDBNull, or duplicate rows being returned with the same primary key.

    Please check your valuse in both tables before merge.

    With Thanks and Regards
    Sambath Raj.C
    click "Proposed As Answer by" if this post solves your problem or "Vote As Helpful" if a post has been useful to you
    Happy Programming!

    • Marked as answer by Alexander Sun Wednesday, December 26, 2012 3:01 AM
    Friday, December 21, 2012 9:59 AM

All replies