There were many similar questions in StackOverFlow but none gave an answer..
when I click on "Add New" button of RadGrid, I get below error:
Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
HTML code:
<telerik:GridTemplateColumn DataField="BURelationship" UniqueName="BURelationship" HeaderText="Relationship" SortExpression="BURelationship">
<ItemTemplate>
<asp:Label ID="lblRelationship" Text='<%# Eval("BURelationship") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlRelationship" runat="server" Width="150" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
C# code:
public DataTable _dtBU;
protected void rgBU_ItemDataBound(object sender, GridItemEventArgs e)
{
try
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
_dtBU = SDM.BU.GetBU();
GridEditableItem item = e.Item as GridEditableItem;
DropDownList rlist = item.FindControl("ddlRelationship") as DropDownList;
rlist.DataTextField = "RName";
rlist.DataValueField = "RID";
rlist.DataSource = SDM.BU.GetAllRelationship();
rlist.DataBind();
foreach (DataRow dr in _dtBU.Rows)
{
if (dr["ID"].ToString() == item.GetDataKeyValue("ID").ToString())
{
rlist.SelectedValue = dr["BURelationship"].ToString();
break;
}
}
}
}
catch (Exception ex)
{
}
}
protected void rgBU_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
_dtBU = SDM.BU.GetBU();
rgBU.DataSource = _dtBU;
}
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;
}
#endregion
Database Table Structure:
In this Table, RfoStatusID is the foreign Key.
DataSet Table Adapter Structure: (DLL)
Stored Procedure to bind the DropDownList is
ALTER PROCEDURE [dbo].[SDM_Select_Relationship]
AS
BEGIN
SET NOCOUNT ON;
SELECT distinct [RID], [RName]
FROM [SDM_DB].[dbo].[SDM_Master_Relationship](NOLOCK)
ORDER BY [RID]
END
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
I even tried to follow this link: ASP.NET dataset getdataBy Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign key constraints but still this error remains the same. Please someone help me to resolve it.