none
Getting error "This constraint cannot be enabled as not all values have corresponding parent values." not sure why RRS feed

  • Question

  • Hi all;

    Okay here is what is going on.

    I have a controller object (UpdateController) that is cycling through a list of person_id.

    I have a DbController object that is created and it opens a connection to the DB and is passed around. The DbController has a fill method that takes in a dataset and an sql statement.  

            public bool FillDataSet(string strSqlStatement, string strDataTableName, ref DataSet aDataSet)
            {
                bool bResult = false;
                try
                {
    
                    mDbCommand = mDbConn.CreateCommand();
                    mDbCommand.CommandText = strSqlStatement;
                    mDataObject.SelectCommand = mDbCommand;
                    mDataObject.Fill(aDataSet, strDataTableName);
                    bResult = true;
                }
                catch(OdbcException e)
                {
                    myLog.LogMessage(MessageType.Error, "DBController", "FillDataSet", "Problem occurred while trying to fill dataset from " + strDataTableName + " : " + e.Message);
                }
                return bResult;
            }

    I have an object that handles the creation of an xml based on data pulled from the DB based on the person_id (PersonHandler). this object creates a new dataset then fills data tables from the DB. (Personnel, card, ...) it then creates the data relations between the tables and does some work.

    So when the program starts the UpdateController generates the list of Person_IDs. It then creates the DBController and opens the DB connection. It then moves to the first person_ID and creates a new PersonHandler, passing in the person_ID and the DBController. The PersonHandler then fills a "person" data table with the person's data and a PersonCard table using a join between the card table(db) and the person table(db) joined on the person_ID in both tables. It then creates a relation between the two tables on the person_ID. After doing some work the PersonHandler is done and the UpdateController moves to the next person_ID and creates a new PersonHandler object.

    The first time through, the person table has 1 entry and the PersonCard table has 0 entries. the second iteration the person table has 1 entry and the PersonCard table has 1 entry. but when i go to create the relation between the Person and PersonCard tables I get the "This constraint cannot be enabled as not all values have corresponding parent values." The Person_ID field in both tables contain the same value. Any idea what could be causing this?


    Shawn

    Tuesday, July 3, 2012 3:52 PM

Answers

  • Hi TinMgAye;

    Turns out it was a hardcoded PersonID in the SQL string that generates the person table. It was set to the first person's ID.

    Operator error.


    Shawn

    Tuesday, July 3, 2012 4:29 PM

All replies

  • "This constraint cannot be enabled as not all values have corresponding parent values."

    The above error nature is because there are no all parent values available to reference for given relationship.

    I believe you are using DataRelation.Add(.....) methods to create a relationship between tables. There is one overload for that method where you can say not to force in creation of Constraints.

    Please refer to this MSDN reference http://msdn.microsoft.com/en-us/library/5a2hh46x

    Hope this helps


    • Edited by TinMgAye Tuesday, July 3, 2012 4:19 PM
    Tuesday, July 3, 2012 4:19 PM
  • Hi TinMgAye;

    Turns out it was a hardcoded PersonID in the SQL string that generates the person table. It was set to the first person's ID.

    Operator error.


    Shawn

    Tuesday, July 3, 2012 4:29 PM