none
This constraint cannot be enabled as not all values have corresponding parent values

    Question

  • Good Day All

    i have a function that builds a Dataset from 3 Xml Files. Let me take this time to explain the xml files.

    There is Subjects.xml, this xml contains all the subjects and i have XML_Venue.xml that contains all the venues and i have TimeTableFull.xml it contains the times,Venues that the subjects will be attended at. Now that means TimeTableFull.xml has many occurances of subjects but on Different venues or same venues but different times. The Following code builds a dataset from the xml's

     

    private
     DataSet CreateDataSet()
    
     {
    
     DataColumn[] keys = new
     DataColumn[1];
    
     DataSet dsFinalTimeTable = new
     DataSet();
    
     DataTable tbldt;
    
    
    
     tbldt = new
     DataTable("Subjects"
    );
    
     //Add Staff Table
    
    
     XmlDataDocument xmlDatadocStaff = new
     XmlDataDocument();
    
     xmlDatadocStaff.DataSet.ReadXml(@"J:\Pilot Project\App_Data\Subjects.xml"
    );
    
     tbldt = xmlDatadocStaff.DataSet.Tables["Subjects"
    ];
    
     keys = new
     DataColumn[1];
    
     keys[0] = tbldt.Columns["ID"
    ];
    
     tbldt.PrimaryKey = keys;
    
     dsFinalTimeTable.Tables.Add(tbldt.Copy());
    
    
    
    
    
     //Add Venue Table
    
    
     tbldt = new
     DataTable("Venue"
    );
    
     XmlDataDocument xmlDatadocVenue = new
     XmlDataDocument();
    
     xmlDatadocVenue.DataSet.ReadXml(@"J:\Pilot Project\App_Data\XML_Venue.xml"
    );
    
     tbldt = xmlDatadocVenue.DataSet.Tables["VENUE"
    ];
    
     keys = new
     DataColumn[1];
    
     keys[0] = tbldt.Columns["ID"
    ];
    
     tbldt.PrimaryKey = keys;
    
     
    
     dsFinalTimeTable.Tables.Add(tbldt.Copy());
    
    
    
     //TimeTable
    
    
     tbldt = new
     DataTable("TimeTable"
    );
    
     XmlDataDocument xmlDatadocTimeTable = new
     XmlDataDocument();
    
     xmlDatadocTimeTable.DataSet.ReadXml(@"J:\Pilot Project\App_Data\TimeTableFull.xml"
    );
    
     tbldt = xmlDatadocTimeTable.DataSet.Tables[0];
    
     keys = new
     DataColumn[1];
    
     keys[0] = tbldt.Columns["ID"
    ];
    
     tbldt.PrimaryKey = keys;
    
     dsFinalTimeTable.Tables.Add(tbldt.Copy());
    
    
     //Setup RelationsTimeTable//
    
    
     DataRelation VenuesRelations = new
     DataRelation("VenueRel"
    , dsFinalTimeTable.Tables["Venue"
    ].Columns["ID"
    ], dsFinalTimeTable.Tables["Appointment"
    ].Columns["ID"
    ]);
    
     DataRelation ModuleRelations = new
     DataRelation("ModuleRel"
    ,dsFinalTimeTable.Tables["Subjects"
    ].Columns["ID"
    ],dsFinalTimeTable.Tables["Appointment"
    ].Columns["subjectid"
    ]);
    
     
    
     dsFinalTimeTable.Relations.Add(VenuesRelations);
    
     dsFinalTimeTable.Relations.Add(ModuleRelations);
    
    
    
     return
     dsFinalTimeTable;
    
     } 
    




    and my problems comes when i have have to add relations  on the modulerelations

     

    dsFinalTimeTable.Relations.Add(ModuleRelations) ;
    
    i receive the Following error :

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


    and i tried to use this line of code to remove this integrity enforcement

    dsFinalTimeTable.EnforceConstraints = false;

    and this left me with an empty grid and this does not look correct.

    Can someone assist me. i have attached the 3 xml files.

     

    http://www.vbforums.com/attachment.php?attachmentid=79604&d=1280784905

    http://www.vbforums.com/attachment.php?attachmentid=79605&d=1280784953


    http://www.vbforums.com/attachment.php?attachmentid=79606&d=128078500



    Thanks


    Vuyiswa Maseko
    Monday, August 02, 2010 9:45 PM

Answers

  • Hello,

    The exception occurs because you have only 30 subjects (if i made no mistake) in Subjects.xml, the ID of the subjects ranges from 1 to 30. However, in your TimeTableFull.xml file, the subjectId is out of the range of 30.

    To fix the exception, you need to make sure the subjectid is not out of range of the ID in Subjects.xml or create a complete new xml file for that.

    Best regards

    • Proposed as answer by Roahn Luo Monday, August 09, 2010 4:47 AM
    • Marked as answer by Vuyiswa Maseko Monday, August 09, 2010 10:16 AM
    Friday, August 06, 2010 10:39 AM

All replies

  • Hello,

    The exception occurs because you have only 30 subjects (if i made no mistake) in Subjects.xml, the ID of the subjects ranges from 1 to 30. However, in your TimeTableFull.xml file, the subjectId is out of the range of 30.

    To fix the exception, you need to make sure the subjectid is not out of range of the ID in Subjects.xml or create a complete new xml file for that.

    Best regards

    • Proposed as answer by Roahn Luo Monday, August 09, 2010 4:47 AM
    • Marked as answer by Vuyiswa Maseko Monday, August 09, 2010 10:16 AM
    Friday, August 06, 2010 10:39 AM
  • Thanks that is exactly the Problem.

     

    Thank you


    Vuyiswa Maseko
    Monday, August 09, 2010 10:16 AM