Comma in concatenate SELECT statement causing "Failed to enable constraints" error RRS feed

  • Question

  • I'm new to the forums so hopefully I've placed this question in the correct thread.  I have a table adapter setup and my GetData() method uses a standard select statement as shown below:

    SELECT own_id, lname + ', ' + fname AS name FROM employee

    The statement executes just fine in the query builder preview and on my SQL Enterprise Manager but when built, the page gives this error:

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

    Line 799:            this.Adapter.Fill(dataTable);

    If I remove the comma from the concatenation, such as SELECT lname + ' ' + fname, the page loads perfectly fine.  Any thoughts?

    FYI, I'm using Visual Studio 2010 Professional w/ .NET 4.0 in C#.

    Wednesday, September 7, 2011 4:07 PM


  • Hi,

    Thanks for your post.

    I think you can try to use the following ways to find the source of the error:

    1. After attempting 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.

    2. 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.

    I hope this can help you.


    Have a nice day,

    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 9, 2011 8:01 AM