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

  • Question

  • User-319370498 posted

    I get this error when I run my page with my localhost, but when I run the query in my dataset it doesn't show an error. I'm working with an MySql database.

    Can somebody help me?

    This is the error: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

    Sunday, July 17, 2011 4:12 PM

Answers

  • User-1694870838 posted

    Hi,

    Here is a similar sample with issue:

                foreach(var item in p.GetSelectedPackage(DropDownList1.SelectedValue))
                {
                    string PackageName = item.PackageName;
                    int PackageID = item.PackageID;
                    string PackageDiscription = item.PackageDiscription;

                    Label1.Text = "Name: " + PackageName;
                    Label1.Visible = true;
                    Label2.Text = "ID: " + PackageID;
                    Label2.Visible = true;
                    Label3.Text = "Discription: " + PackageDiscription;
                    Label3.Visible = true;
                    ListBox2.Visible = true;

                    foreach (var software in s.GetSelectedIndexSoftware(PackageID))   <----- this is there the error come.
                    {
                        ListBox2.Items.Add(software.SoftwareName);
                    }
                }

     

    the method GetSelectedIndexSoftware(packageID) looks like this:

    SELECT        SoftwareName
    FROM            Software
    WHERE        (PackageID = @PackageID)

     

    all i got in the database now is:

    insert into Package values('1', '1')
    insert into Package values('2', '2')

    insert into Software values('1', '1', '1', null)
    insert into Software values('2', '2', '2', null)
    insert into Software values('3', '3', '3', null)
    insert into Software values('4', '4', '4', null)

    it was because the GetSelectedInsexSoftware() query was only getting the SoftwareName. that was not enough. so when i expanded the select to get all info it worked.

    Could you please display you Sql clause and your table structure?

    Or you can refer to this thread:http://forums.asp.net/p/1154874/1901799.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 22, 2011 4:18 AM

All replies

  • User-1946294156 posted

    Pull the data directly from your database and look to see if your Primary Key is repeated somewhere.  This is I see happen all the time. 

    Sunday, July 17, 2011 7:48 PM
  • User-319370498 posted

    Pull the data directly from your database and look to see if your Primary Key is repeated somewhere.  This is I see happen all the time. 

    Every row is unique, I use autoincrement so.

    Monday, July 18, 2011 7:34 AM
  • User-1694870838 posted

    Hi,

    Here is a similar sample with issue:

                foreach(var item in p.GetSelectedPackage(DropDownList1.SelectedValue))
                {
                    string PackageName = item.PackageName;
                    int PackageID = item.PackageID;
                    string PackageDiscription = item.PackageDiscription;

                    Label1.Text = "Name: " + PackageName;
                    Label1.Visible = true;
                    Label2.Text = "ID: " + PackageID;
                    Label2.Visible = true;
                    Label3.Text = "Discription: " + PackageDiscription;
                    Label3.Visible = true;
                    ListBox2.Visible = true;

                    foreach (var software in s.GetSelectedIndexSoftware(PackageID))   <----- this is there the error come.
                    {
                        ListBox2.Items.Add(software.SoftwareName);
                    }
                }

     

    the method GetSelectedIndexSoftware(packageID) looks like this:

    SELECT        SoftwareName
    FROM            Software
    WHERE        (PackageID = @PackageID)

     

    all i got in the database now is:

    insert into Package values('1', '1')
    insert into Package values('2', '2')

    insert into Software values('1', '1', '1', null)
    insert into Software values('2', '2', '2', null)
    insert into Software values('3', '3', '3', null)
    insert into Software values('4', '4', '4', null)

    it was because the GetSelectedInsexSoftware() query was only getting the SoftwareName. that was not enough. so when i expanded the select to get all info it worked.

    Could you please display you Sql clause and your table structure?

    Or you can refer to this thread:http://forums.asp.net/p/1154874/1901799.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 22, 2011 4:18 AM