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

Last Reply on Aug 26, 2015 08:50 AM By Richa

Posted on Aug 26, 2015 02:55 AM

I am facing this error in binding of DropDownList in Grid.

I am using TableAdapter inside DataSet.xsd (DLL)

.aspx.cs code to bind DropDownList inside Grid:

GridEditableItem item = e.Item as GridEditableItem;

            DropDownList rlist = item.FindControl("ddlRelationship") as DropDownList;
            rlist.DataTextField = "RName";              
            rlist.DataValueField = "RID";
            rlist.DataSource = SDM.BU.GetAllRelationship();

            foreach (DataRow dr in _dtBU.Rows)
                if (dr["ID"].ToString() == item.GetDataKeyValue("ID").ToString())
                    rlist.SelectedValue = dr["BURelationship"].ToString();    

SDM.BU class file code (BLL):

#region GET
    public SDMDAL.SDM_Master_BUDataTable GetBU()
        return Adapter.GetBU();

    public DataTable GetAllRelationship()
        DataTable dt = Adapter.GetRelationship();
        return dt;

Stored Procedure to bind the DropDownList is 

ALTER PROCEDURE [dbo].[SDM_Select_Relationship]

    SELECT distinct [RID], [RName] 
    FROM [SDM_DB].[dbo].[SDM_Master_Relationship](NOLOCK)

Database Table which I am using to bind the DropDownList:


here, RfoStatusID is the foreign Key.

DataSet TableAdapter


Please let me know the cause of this error and how to resolve it ? I am unable to understand why this error is coming. Whenever I click on Add New button of RadGrid, Add panel opens with this Logging Exception. Please let me know What is wrong in my code ?  NOTE: I am very new in Table Adapter method and 1st time using it.  Please reply

Posted on Aug 26, 2015 02:55 AM

Posted on Aug 26, 2015 03:39 AM Modified on on Aug 26, 2015 03:41 AM

@Andrea: Thank you for the reply.

In your suggested solution, I got a useful link:  http://stackoverflow.com/questions/6014365/asp-net-dataset-getdataby-failed-to-enable-constraints-one-or-more-rows-contain

tried to follow the same but error still remains the same.

Always I am getting error at below line:

rlist.DataSource = SDMBU.BUTest.GetAllRelationship();

at below function:


Please someone let me know what shall I change in my code? and what is the reason of this error ? 

Please reply

Posted on Aug 26, 2015 05:14 AM

Hi Richa,

Please check the Adapter.GetRelationship() method what the result you are getting. Else share your all code so that i can help you.

Posted on Aug 26, 2015 08:50 AM

I created a new TableAdapter for binding the DropDownList and its working fine now. Previously I was using 1 TableAdapter to bind Grid as well as this DropDownList so only it was showing error.

Thanks all for the help