Link to home
Start Free TrialLog in
Avatar of kwh3856
kwh3856Flag for United States of America

asked on

This constraint cannot be enabled as not all values have corresponding parent values. Attempting to create data relation

I am trying to create a relation between two tables and get this error message.  I am not sure I understand what constraint it is talking about.  Any ideas are greatly appreciated.

Thanks
Kenny


protected void PopulateProviderTable()
    {

       
        SqlDataAdapter sqlDA = CreateProviderAdapter();
        SqlDataAdapter sqlDAphyins = CreateProviderInsAdapter();
        SqlDataAdapter sqlDAphyspecial = CreateProviderSpecialAdapter();
        SqlDataAdapter sqlDAphyspecialproc = CreateProviderSpecialProcAdapter();
       
       
        errormessage.Text = ProviderSearch;
        errormessage2.Text = SearchProviderIns;
        errormessage3.Text = SearchProvSpecialty;

       // Create Relations - Setup Key Fields
        DataColumn doctorId = HDSDataSet.Tables["PROVIDER"].Columns["PHYSICIAN_NPI"];
        DataColumn insurId = HDSDataSet.Tables["PHYSINS"].Columns["PHYSICIAN_NPI"];
        DataColumn specialtiesId = HDSDataSet.Tables["PHYS_SPECIALTIES"].Columns["PHYSICIAN_NPI"];

        // Create Relations - Build Relation
        DataRelation specialtiesRelation = new DataRelation("specialtiesRelation", doctorId, specialtiesId);
        DataRelation insurRelation = new DataRelation("insurRelation", doctorId, insurId);
        HDSDataSet.Relations.Clear();
        HDSDataSet.Relations.Add(insurRelation);
        HDSDataSet.Relations.Add(specialtiesRelation);----------------<<<<<<<<<<<---------------Line with ERROR
Avatar of imitchie
imitchie
Flag of New Zealand image

it means that in your underlying tables, not all
PROVIDERs have a record in PHYS_SPECIALTIES  (or the other way around)
Avatar of kwh3856

ASKER

Additional Info
When I look at the specialtiesRelation in the Watch table the ChildKeyRelation shows Null

If I look at the insurRelation in the watch table, the ChildKeyConstraint shows to be insurRelation

NOT SURE WHY

Avatar of kwh3856

ASKER

The provider table has three records with the physician_npi set to 100, 200, 300 respectively.  The PHYS_SPECIALITIES table has three records with the same data in the physician_NPI.  Maybe I am not selecting them in my select statement.  I will check.

Thanks
Kenny
Avatar of kwh3856

ASKER

When I look in my dataset using the watch command, the PHYS_SPECIALTIES tables show three records which is what I expected.  Any other ideas?

Thanks
Kenny
Avatar of kwh3856

ASKER

Also, does each of the table HAVE to have a record for the corresponding table?  I did not know that was a requirement for a relation to be setup.

Thanks
Kenny
how many PROVIDER records do you have?
try this instead

DataRelation specialtiesRelation = new DataRelation("specialtiesRelation", doctorId, specialtiesId, false);
ASKER CERTIFIED SOLUTION
Avatar of imitchie
imitchie
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kwh3856

ASKER

Thank you very much.  That resolved my problem.