[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

You are viewing reply posted by: Richa on Aug 26, 2015 08:50 AM.
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