none
Failed to enable constraints when filling data tables. RRS feed

  • Question

  • Hello,

    VS 2005 using Typed Datasets.

    I have this problem that I am trying to fill 2 data tables 'Orders' (parent table) and 'OrderDetails' (child table).

    In the dataset designer I have added the relationship between them.

     
    Code Snippet

    Me.DsAddComponetAndEquipment1.EnforceConstraints = False
                Me.TA_Orders_dsCodered1.ClearBeforeFill = False
                Me.TA_Orders_dsCodered1.Fill(Me.DsAddComponetAndEquipment1.Orders)
                Me.TA_OrderDetails_dsCodeRed1.Fill(Me.DsAddComponetAndEquipment1.OrderDetails)
               Me.DsAddComponetAndEquipment1.EnforceConstraints = True


    I what I have tried a different combination of the above. I know that by default the data table is cleared, so if there are values in the child table, then it might throw this error. So setting it to false didn't work.

    When i enforce constraints to false, but as soon as I set it to true after the data tables are filled, it will throw the error.

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

    Many thanks for any assistance,

    Steve
    Tuesday, July 31, 2007 10:47 AM

Answers

  • Long time since your post, but since it is unanswered I will post a suggestion.

    If the data is causing the problem this is a good and easy way to find the specific data field that is causing the problem.

    Without turning off EnforceConstraints. After trying to fill the typed dataset - Check the HasErrors property for each DataTable in the DataSet. When you find the datatable with HasErrors=True, invoke the GetErrors method on this table. The GetErrors method returns a collection of DataRows and you can invoke the .RowError property on each of the rows to see exactly what the problem is.

    I usually just do it directly in the Watch-window in Visual Studio by adding a watch on <NameOfDataSetWithErrors>.<NameOfDataTableWithErrors>.GetErrors()

    You must declare the dataset outside of the try-catch so that you can still access it in the catch-section by the way.

    (This was copy-pasted from a blog post.)


    http://www.fransson.net
    • Marked as answer by steve1_rm Monday, April 11, 2011 4:40 AM
    Monday, December 20, 2010 8:42 AM

All replies

  • I think the problem might be in the database not your code.  You probably have an order with no details or details without a order record.
    Tuesday, July 31, 2007 12:40 PM
  • Hello,

     

    Thanks for the reply.

     

    The data is clean there is nothing wrong with any missing foreign keys,

     

    Thanks for any more advice,

     

    Steve

     

    Tuesday, July 31, 2007 1:21 PM
  • Long time since your post, but since it is unanswered I will post a suggestion.

    If the data is causing the problem this is a good and easy way to find the specific data field that is causing the problem.

    Without turning off EnforceConstraints. After trying to fill the typed dataset - Check the HasErrors property for each DataTable in the DataSet. When you find the datatable with HasErrors=True, invoke the GetErrors method on this table. The GetErrors method returns a collection of DataRows and you can invoke the .RowError property on each of the rows to see exactly what the problem is.

    I usually just do it directly in the Watch-window in Visual Studio by adding a watch on <NameOfDataSetWithErrors>.<NameOfDataTableWithErrors>.GetErrors()

    You must declare the dataset outside of the try-catch so that you can still access it in the catch-section by the way.

    (This was copy-pasted from a blog post.)


    http://www.fransson.net
    • Marked as answer by steve1_rm Monday, April 11, 2011 4:40 AM
    Monday, December 20, 2010 8:42 AM