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

  • Question

  • Hey there. i am having a problem. i want to get info on a package from database and get the software linked to that package..

    my db looks like this.

    create table Package
    PackageID int identity,
    PackageName varchar(50) not null,
    PackageDiscription varchar(max) not null,
    primary key (PackageID)


    create table Software
    SoftwareID varchar(50) not null,
    SoftwareName varchar(50) not null,
    DownloadPath varchar(100) not null,
    PackageID int,
    Primary key (SoftwareID),
    Foreign Key (PackageID) references Package on delete cascade on update cascade


    what i am trying to do is this:

            protected void BtnPackageSelect_Click(object sender, EventArgs e)
                SoftwareTableAdapters.PackageTableAdapter p = new SoftwareTableAdapters.PackageTableAdapter();
                SoftwareTableAdapters.SoftwareTableAdapter s = new SoftwareTableAdapters.SoftwareTableAdapter();

                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.


    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)


    where all software's null have been updated with 1

    am fairly new to coding so am a bit lost.. hopeone someone can help me out to find the problem

    • Moved by Bob Beauchemin Sunday, January 9, 2011 4:23 AM Moved to a possibly more relevent forum (From:.NET Framework inside SQL Server)
    Saturday, January 8, 2011 4:20 PM


  • Error found. 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.

    • Marked as answer by VMazur Monday, January 10, 2011 11:56 AM
    Monday, January 10, 2011 9:10 AM